The Code is as follows:
<Script type = "text/javascript">
String. prototype. Trim = function (){
Var m = this. match (/^ \ 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 ()));
}
String. prototype. isTel = function ()
{
// "Compatible format: Country Code (two to three digits)-area code (two to three digits)-telephone number (seven to eight digits)-extension number (three digits )"
// Return (/^ ([0 \ +] \ d {2, 3 }-)? (0 \ d {2, 3 })-)? (\ D {7, 8}) (-(\ d {3 ,}))? $/. Test (this. Trim ()));
Return (/^ ([0 \ +] \ d {2, 3 }-)? (0 \ d {2, 3})-) (\ d {7, 8}) (-(\ d {3 ,}))? $/. Test (this. Trim ()));
}
Function chkForm (){
With (document. form1 ){
If (tel. value. isMobile () | tel. value. isTel ()){
Tel. value = tel. value. Trim ();
Alert ("your phone number/mobile phone number is:" + tel. value );
Return true;
}
Else {
Alert ("enter the correct mobile phone number or phone number \ n For example: 13916752109 or 0712-3614072 ");
Tel. focus ();
Return false;
}
}
}
</Script>
<Form name = "form1" method = "post" action = "">
<Input type = "text" name = "tel" value = "13916752109" size = "15"/>
<Input type = "button" value = "test" onclick = "return chkForm ()"/>
</Form>