I have this form in my app and I will submit it via AJAX, but I want to use HTML5 for client-side validation. So I want to be able to force the form validation, perhaps via jQuery.
I want to trigger the validation without submitting the form. Is it possible?
This worked form me to display the native HTML 5 error messages with form validation.
Note: RegForm is the
form id
.Reference
Hope helps someone.
May be late to the party but yet somehow I found this question while trying to solve similar problem. As no code from this page worked for me, meanwhile I came up with solution that works as specified.
Problem is when your
<form>
DOM contain single<button>
element, once fired, that<button>
will automatically sumbit form. If you play with AJAX, You probably need to prevent default action. But there is a catch: If you just do so, You will also prevent basic HTML5 validation. Therefore, it is good call to prevent defaults on that button only if the form is valid. Otherwise, HTML5 validation will protect You from submitting. jQuerycheckValidity()
will help with this:jQuery:
Code described above will allow You to use basic HTML5 validation (with type and pattern matching) WITHOUT submitting form.