JS support for 158, 159 the beginning of the phone number verification _ form effects

Source: Internet
Author: User
Added to the 158, 159 the beginning of the phone number verification.
Copy Code code as follows:

Remove string and tail space
String.prototype.Trim = function () {
var m = This.match (/^\s* (\s+ (\s+\s+) *) \s*$/);
return (M = = null)? "": m[1];
}
Verify Legal mobile phone number
String.prototype.isMobile = function () {
Return (/^ (?: 13\d|15[89])-?\d{5} (The \d{3}|\*{3}) $/.test (this. Trim ());
}


Should be an instance:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "lang=" gb2312 "> <pead> <title> Example: Verify mobile phone number </title > <meta http-equiv= "content-type" content= "text/html; charset=gb2312 "/> <script type=" Text/javascript "> String.prototype.Trim = function () {var m = THIS.MATC H (/^\s* (\s+ (\s+\s+) *) \s*$/); return (M = = null)? "": m[1]; } String.prototype.isMobile = function () {return (/^ (?: 13\d|15[89])-?\d{5} (\d{3}|\*{3}) $/.test (this. Trim ()); } function Chkform (oform) {if (OForm.tel.value.isMobile ()) {Oform.tel.value=oform.tel.value.trim (); return true; else {alert ("Please enter the correct cell phone number!"); return false; } </script> </pead> <body> <form name= "Form1" method= "Post" action= "" onsubmit= "return chkfor M (this); " > <input type= "Text" name= "tel" value= "15812345678 "size="/><input type= "Submit" value= "submitted"/> </form> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.