10 examples of 'jquery validate form before submit' in JavaScript

Every line of 'jquery validate form before submit' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
177function validateForm() {
178 if ($("input#username").val() && $("input#password").val()) {
179 return true;
180 } else {
181 return false;
182 }
183}
203function validateForm () {
204 var valid = true; /* "true" is all good news */
205 if ($.fn.validate === undefined)
206 return valid;
207
208 var validator = $top.validate();
209
210 // Look at the inputs for each non-hidden step in our form
211 $("div.ui-dform-step:not(:hidden) input", $top).each(function () {
212 var tvalid = validator.element(this);
213 if (tvalid === undefined) // Agnostic? Force a value!
214 tvalid = true;
215 valid &= tvalid;
216 $.dbgpr("validateForm:", this.name, ":", tvalid);
217 })
218
219 $.dbgpr("validateForm:", this.name, " is ", valid);
220 return valid;
221}
85function validate(form) {
86 var i = 0;
87 jQuery("input.required").each(function() {
88 if(jQuery(this).val() == '') {
89 jQuery(this).focus();
90 return false;
91 }
92 i++;
93 });
94 if(i < jQuery("input.required").length) {
95 return false;
96 } else {
97 return true;
98 }
99}
86function validate(form) {
87 if(jQuery("#access_id").val() == '') {
88 jQuery("#access_id").parent().parent().addClass('has-warning');
89 return false;
90 } else if(jQuery("#access_key").val() == '') {
91 jQuery("#access_key").parent().parent().addClass('has-warning');
92 return false;
93 } else if(jQuery("#bucket").val() == '') {
94 jQuery("#bucket").parent().parent().addClass('has-warning');
95 return false;
96 } else if(jQuery("#hostname").val() == '') {
97 jQuery("#hostname").parent().parent().addClass('has-warning');
98 return false;
99 }
100 return true;
101}
8function validate_form_inputs( submittedForm ) {
9
10 var goodToGo = true;
11 var cntr = 1;
12
13 $( submittedForm ).find('.required').each( function( index ) {
14 if( $(this).val() === '' || $(this).val() === 0 ) {
15 $(this).addClass('requires-value').siblings( '.validation-notice-dv' ).fadeIn();
16 goodToGo = false;
17 }
18 $(this).on( 'change', function() {
19 if( $(this).val() !== '' || $(this).val() !== 0 ) {
20 $(this).removeClass('requires-value').siblings( '.validation-notice-dv' ).fadeOut('fast');
21 }
22 });
23 if ( cntr === 1 ) {
24 var thisPos = $(this).offset();
25 $(window).scrollTop( thisPos.top - 200 );
26 }
27 cntr++;
28 });
29 return goodToGo;
30}
34function MySubmitForm() {
35 if (passThroughFormSubmit) {
36 return true;
37 }
38 Asirra_CheckIfHuman(HumanCheckComplete);
39 return false;
40}
73function verifyForm() {
74 var result = true;
75
76 $("#contact-form > .form-group").each( (i, item) => {
77 var test = $(item).attr('class');
78 result = (verifyFormGroup($(item))) ? result : false;
79 });
80
81 return result;
82}
646function validate($form) {
647 values = {};
648 $.each($form.serializeArray(), function(i, field) {
649 values[field.name] = field.value;
650 });
651 values['_token'] = CSRFToken;
652
653 $.ajax({
654 url: validationUrl,
655 method: 'POST',
656 data: values,
657 success: function(data) {
658 $form.submit();
659 },
660 error: function(err) {
661 console.log(err);
662 $('.error-message').text('');
663 $('.text-input, .text-area, .chosen-container').removeClass('error');
664
665 $.each(err.responseJSON.errors, function(fieldName, errors) {
666 var $field = $('#'+fieldName);
667 $field.addClass('error');
668 $field.siblings('.error-message').text(errors[0]);
669 });
670 }
671 });
672 }
19function submitFormPost() {
20 var type = $('type').value;
21
22 if (type == 'image' || type == 'audio') {
23 return $('formPost').submit();
24 }
25
26 form = new ValidateForm($('formPost'),"admin/post/verify");
27 form.errorElem = $('error_messages');
28 form.successCallback = function() {callbackPostSuccess();};
29 return form.submit();
30}
56function validateForm () {
57 if (checkField('#name', 'Name') &&
58 checkField('#email', 'Email') &&
59 checkEmail('#email') &&
60 checkField('#message', 'Message')) {
61 return true;
62 }
63 return false;
64}

Related snippets