In the user login, user registration often need to check the user name, such as mailbox, mobile phone number, commonly used expressions.
The following is the collation of the mailbox and mobile phone number expression validation:
function CheckUser () {var userName = document.getElementById ("User_inp"). Value;var semailreg =/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$/;var Snumreg =/^\d+$/if (username.length<=0 | | username== "Please enter your email account/Phone number") {Showtips ("username cannot be empty!") "); return false;} if (Snumreg.test (userName)) {if (username.length!=11) {showtips ("phone number is not formatted correctly! "); return false;} Showtips (""); return true;} if (!semailreg.test (UserName)) {showtips ("email input is wrong, please re-enter!") "); return false;} Showtips (""); return true;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
JavaScript uses regular expressions to detect the legality of user names