JavaScript uses regular expressions to detect the legality of user names

Source: Internet
Author: User

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

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.