Mobile phone number and phone number legality verification code

Source: Internet
Author: User

Mobile phone number and phone number legality verification code:
In some website phone number and mobile phone number are required, or need to fill in one of them, in order to enhance the authenticity of the site also improve the user experience, generally need to do format validation, the following is an excerpt from the network of a validation code for your reference, hoping to bring a certain help to everyone.
The code is as follows:

functionCheckreg () {//Verify the phone number of the phone number, including paragraph 153,159  if(document.form.phone.value== "" &&document.form.usermobile.value== "") {alert ("Choose at least one of the phone and mobile numbers!" ");     Document.form.phone.focus (); return false; }   if(Document.form.phone.value! = ""){     varPhone=Document.form.phone.value; varp1=/^ ([0\+]\d{2,3}-)? ( 0\d{2,3})? (\d{7,8}) (-(\d{3,}))? $/; varMe=false; if(P1.test (phone)) {Me=true; }    if(!me) {Document.form.phone.value= ' '; Alert (' Sorry, the phone number you entered has an error. Between the area code and the phone number, use-split ');       Document.form.phone.focus (); return false; }   }   if(Document.form.UserMobile.value! = ""){     varmobile=Document.form.UserMobile.value; varreg0=/^13\d{5,9}$/; varreg1=/^153\d{4,8}$/; varreg2=/^159\d{4,8}$/; varreg3=/^0\d{10,11}$/; varmy=false; if(Reg0.test (MOBILE)) my=true; if(Reg1.test (MOBILE)) my=true; if(Reg2.test (MOBILE)) my=true; if(Reg3.test (MOBILE)) my=true; if(!my) {Document.form.UserMobile.value= ' '; Alert (' Sorry, the phone or PHS number you entered is wrong. ‘);       Document.form.UserMobile.focus (); return false; }     return true; } }

The above code can achieve the validity of the phone number and mobile phone number format validation.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8394

For more information, refer to: http://www.softwhy.com/javascript/

Mobile phone number and phone number legality verification code

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.