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]