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