JQuery Validate validation, custom rules and messages (reprint)

Source: Internet
Author: User

Reprinted from: http://blog.163.com/zhao_jinggui/blog/static/169620429201172942347465/

$ (). Ready (function() {JQuery.validator.addMethod ("IsMobile",function(value, Element) {varLength =value.length; varMobile =/^ ((13[0-9]{1}) | ( 15[0-9]{1})) +\d{8}) $/; return This. Optional (Element) | | (Length = = &&mobile.test (value)); }, "Please fill in your mobile phone number correctly"); JQuery.validator.addMethod ("Isphone",function(value, Element) {varLength =value.length; varPhone =/(^ (\d{3,4}-)? \d{6,8}$) | (^ (\d{3,4}-)? \d{6,8} (-\d{1,5})? $) | (\d{11})/; return This. Optional (Element) | |(Phone.test (value));},"Please fill in the correct phone number"); JQuery.validator.addMethod ("Ischinese",function(value, Element) {varChinese =/^[a-za-z\u4e00-\u9fa5]+$/i; return This. Optional (Element) | |(Chinese.test (value));},"Only input Chinese characters"); JQuery.validator.addMethod ("Ismypassword",function(value, Element,param) {//var specialstr =/[!,[email protected]#$%^&*?_~]/;//var numberstr=/^ (\d+[a-za-z]\w*) | ([a-za-z]+\d\w*) $/;//return this.optional (Element) && (Numberstr.test (value)) && (specialstr.test (value )); varREGU1 =/[a-za-z]/; varregu2=/\d/; varRegu3=/[!,[email protected]#$%^&*?_~]/; varb1=regu1.test (value); varB2=regu2.test (value); varb3=regu3.test (value); varb=b1&&b2&&B3; returnb = =eval (param);},"Password must be entered in letters and numbers"); $("#myform"). Validate ({rules: {userName : {required:true, minlength:6, MaxLength:200}, UserEmail: {required:true, Email:true}, Userpwd: {required:true, minlength:8, Ismypassword:true}, Confuserpwd: {required:true, minlength:8, Equalto:"#userPwd"}, Userrname: {required:true, minlength:6, MaxLength:200, Ischinese:true}, Usermphone: {required:true, IsMobile:true}, Userphone: {required:true, Isphone:true}}, messages: {userName: {required:"Please enter user name", minlength:"Character length cannot be less than 6 characters", MaxLength:"Character length cannot be greater than 200 characters"}, UserEmail: {required:"Please enter your email address", Email:"Please enter the correct email address"}, Userpwd: {required:"Please enter your password", minlength:"Character length cannot be less than 8 characters", Ismypassword:"Passwords must consist of numbers, English letters and special characters (!,[email protected]#$%^&*?_~)"}, Confuserpwd: {required:"Please enter a confirmation password", minlength:"Character length cannot be less than 8 characters", Equalto:"Two times password input inconsistency"}, Userrname: {required:"Please enter your real name", minlength:"Character length cannot be less than 6 characters", MaxLength:"Character length cannot be greater than 200 characters", Ischinese:"Only input Chinese characters"}, Usermphone: {required:"Please enter your mobile phone number", IsMobile:"Please enter the correct mobile phone number"}, Userphone: {required:"Please enter your phone number", Isphone:"Please enter the correct phone number"}}, Errorelement:"Em", Success:function(EM) {Em.text (""). AddClass ("Success")); } }); });


/* Forms Validation Style */

em {font/* font not italic *  /font-weight:500; padding-right:1em; Vertical-align:middle; color:red;} Em.error {Background:url (".. /images/unchecked.gif ") no-repeat 0px 0px; padding-left:16px;} em.success {Background:url (".. /images/standard_msg_ok.gif ") no-repeat 0px 0px; padding-left:16px;}


Other Learning materials:
Http://blog.sina.com.cn/s/blog_608475eb0100h3h1.html
Http://www.jb51.net/article/23420.htm

JQuery Validate validation, custom rules and messages (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.