Javascript code verification of mobile phone numbers and phone numbers _ javascript skills

Source: Internet
Author: User
This article mainly describes how to verify the validity of mobile phone numbers and phone numbers by js Code. Mobile phone numbers and phone numbers are mandatory on some websites. To improve user experience, this document describes how to verify the validity of mobile phone numbers and phone numbers by using JavaScript code, mobile phone numbers and phone numbers are mandatory on some websites. To improve user experience, the legality verification is generally required. The Code is as follows: Function Checkreg (){.....

Function Checkreg () {// verify the mobile phone number of the phone number, including, number segment if (document. form. phone. value = "" & document. form. userMobile. value = "") {alert ("either phone number or mobile phone number is required! "); Document. form. phone. focus (); return false;} if (document. form. phone. value! = "") {Var phone = document. form. phone. value; var p =/^ ([\ +] \ d {,}-)? (\ D {,})-)? (\ D {,}) (-(\ d {,}))? $/; Var me = false; if (p. test (phone) {me = true;} if (! Me) {document. form. phone. value = ''; alert ('Sorry, the phone number you entered is incorrect. Use-to separate the area code from the phone number); document. form. phone. focus (); return false ;}} if (document. form. UserMobile. value! = "") {Var mobile = document. form. userMobile. value; var reg =/^ \ d {, }$/; var reg =/^ \ d {, }$/; var reg =/^ \ d {,} $/; var reg =/^ \ d {,} $/; var my = false; if (reg. test (mobile) my = true; if (reg. test (mobile) my = true; if (reg. test (mobile) my = true; if (reg. test (mobile) my = true; if (! My) {document. form. UserMobile. value = ''; alert ('Sorry, the phone number or PHS number you entered is incorrect. '); Document. form. UserMobile. focus (); return false ;}return true ;}}

The above code is to use js to verify whether the mobile phone number and phone number are legal. I hope you will like it.

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.