JS Regular expression verification account, mobile phone number, phone, and e-mail

Source: Internet
Author: User

JS Regular expression verification account, mobile phone number, phone, and e-mail

Effect Experience: http://keleyi.com/keleyi/phtml/jstexiao/15.htm

Verify that the account is valid for validation rules: Letters, numbers, underscores, letters beginning with 4-16 digits.

function CheckUser (str) {varRe=/^[a-za-z]\w{3, the}$/; if(Re.test (str)) {alert ("correct"); }Else{alert ("Error"); }}checkuser ("Jihua_cnblogs");//called

Verify your phone number
Validation rule: 11 digits, starting with 1.

function Checkmobile (str) {varRe= /^1\d{Ten}$/if(Re.test (str)) {alert ("correct"); } Else{alert ("Error"); }}checkmobile ('13800138000');//calledCheckmobile ('139888888889');//Error Example

Verify the phone number verification rule: Area code + number, area code starts with 0, 3-bit or 4-digit number consists of 7-bit or 8-digit numbers between the area code and the number can be no connector, or "-" connection such as 01088888888,010-88888888,0955-7777777

function Checkphone (str) {varRe= /^0\d{2,3}-?\d{7,8}$/; if(Re.test (str)) {alert ("correct"); }Else{alert ("Error"); }}checkphone ("09557777777");//called

Verify Mailbox
Validation rules: Leave your email address in the "first part @ Second part"
The first part: By letter, number, underline, short line "-", Dot "." Composition
Part two: For a domain name, the domain name consists of letters, numbers, short-term "-", the domain name suffix,
and the domain name suffix is generally. xxx or. xxx.xx, a domain name suffix is generally 2-4-bit, such as cn,com,net, now the domain name will be more than 4 bit

 function checkemail (str) { var  Span style= "color: #000000;" > re  =/^ (\w-*\.*) [email protected] (\w-?) + (\.\w{2 ,}) +$/if   (Re.test (str)) {alert (   correct  Span style= "color: #800000;"    > " );  else  {alert (  "  error  "    [email protected]  ); //  call  

JS Regular expression verification account, mobile phone number, phone, and e-mail

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.