jQuery validate: How to add a rule for regular expression validation?

前端 未结 13 1496
忘掉有多难
忘掉有多难 2020-11-22 07:41

I am using the jQuery validation plugin. Great stuff! I want to migrate my existing ASP.NET solution to use jQuery instead of the ASP.NET validators. I am m

13条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 08:40

    You can use the addMethod()

    e.g

    $.validator.addMethod('postalCode', function (value) { 
        return /^((\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d))$/.test(value); 
    }, 'Please enter a valid US or Canadian postal code.');
    

    good article here https://web.archive.org/web/20130609222116/http://www.randallmorey.com/blog/2008/mar/16/extending-jquery-form-validation-plugin/

提交回复
热议问题