简体   繁体   中英

How I can validate my form with existing method written in Javascript?

I have write a validator.js which contain the code for validate rules by regex.

Here is the code I got on the page

    jQuery.validator.addMethod("corePhoneUS", coreFieldValidator.phoneUS, "Please enter a 10 digit phone number. Ex: 801-555-1212");
    jQuery.validator.addMethod("coreZipUS", coreFieldValidator.zipUS, "Please enter a 5 or 9 digit zip code. Ex: 84045, or 84045-1234");

Now I have html form that I want to validate. $("#contactForm").validate() is not working. I have seen no error.

Do someone know how to apply existing method in validate.

Thanks

Make sure that you have applied the validation rules to some input fields on the form:

$('#contactForm').validate({
    rules: {
        someInputElementName: {
            corePhoneUS: true
        },
        someOtherInputElementName: {
            coreZipUS: true
        }
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM