JavaScript Data Validation Class

Source: Internet
Author: User

JavaScript Data Validation Class

/*JavaScript: Authentication class Author: Yang Bo date:201603231, User name authentication 2, password Authentication 3, repeat password verification 4, mailbox verification 5, mobile phone number verification 6, Verification code verification*/varYb_validate =function(){    //User Name Verification     This. Username =function(username) {if(username.length==0)return NewArray (false, ' Please enter user name '); Else if(username.length<6)return NewArray (false, ' User name cannot be less than 6 bits '); Else if(username.length>16)return NewArray (false, ' User name cannot be greater than 16 bits '); Else return NewArray (true, ' input correct '); }    //Password Verification     This. Password =function(password) {if(password.length==0)return NewArray (false, ' Please enter your password '); Else if(password.length<6)return NewArray (false, ' password cannot be less than 6 bits '); Else if(password.length>16)return NewArray (false, ' password cannot be greater than 16 bits '); Else return NewArray (true, ' input correct '); }    //Duplicate Password Verification     This. ConfirmPassword =function(Password,confirm_password) {if(confirm_password.length==0)return NewArray (false, ' Please enter your password '); Else if(confirm_password.length<6)return NewArray (false, ' password cannot be less than 6 bits '); Else if(confirm_password.length>16)return NewArray (false, ' password cannot be greater than 16 bits '); if(Password!=confirm_password)return NewArray (false, ' Two input passwords inconsistent '); Else return NewArray (true, ' input correct '); }    //Mailbox Verification     This. email =function(email) {if(email== "){            return NewArray (false, ' email not filled in '); }        if(Email.search (/^\w+ (-\w+) | ( \.\w+)) *\@[a-za-z0-9]+ ((\.| -) [a-za-z0-9]+] *\. [a-za-z0-9]+$/)! =-1)return NewArray (true, ' input correct '); Else return NewArray (false, ' Mailbox error '); }    //Mobile Verification     This. Mobile =function(MOBILE) {if(mobile== "){            return NewArray (false, ' phone number not filled in '); }        if(mobile.length!==11){            return NewArray (false, ' mobile phone number must be 11-bit '); }        if(Mobile.substr (0,1)!=1){            return NewArray (false, ' mobile phone number is not legal '); }        if(mobile.substr) ==3 | | mobile.substr (a) ==4 | | mobile.substr (ALL) ==5 | | mobile.substr (ALL) ==8){            return NewArray (true, ' input correct '); }        Else{            return NewArray (true, ' input correct '); }    }    //Verification Code Verification     This. Code =function(code) {if(code== "){            return NewArray (false, ' Verification code not filled in '); }        if(code.length!==6){            return NewArray (false, ' Verification code must be 6 bits long '); }        Else{            return NewArray (true, ' input correct '); }    }}//Creating Objectsvar_yb_validate =NewYb_validate ();

JavaScript Data Validation Class

Related Article

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.