Javascript uses regular expressions to check the validity of user names

Source: Internet
Author: User
Tags email account

Javascript uses regular expressions to check the validity of user names

User names such as email addresses and mobile phone numbers are frequently verified during user logon and user registration. common expressions are used.

The expression verification for the email address and mobile phone number is as follows:

 

Function checkUser () {var userName = document. getElementById (user_indium ). value; var sEmailReg =/^ [w-] + (. [w-] +) * @ [w-] + (. [w-] +) + $/; var sNumReg =/^ d + $/if (userName. length <= 0 | userName = enter the email account/mobile phone number) {showTips (the user name cannot be blank !); Return false;} if (sNumReg. test (userName) {if (userName. length! = 11) {showTips (incorrect mobile phone number format !); Return false;} showTips (); return true;} if (! SEmailReg. test (userName) {showTips (Incorrect email address. Please enter it again !); Return false;} showTips (); return true ;}


 

 

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.