The code is as follows:
Copy the code code 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 (2 to 3 digits)-area code (2 to 3 digits)-telephone number (7 to 8 digits)-extension number (3 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/mobile number is:" + tel.value);
return true;
}
else {
alert("Please enter the correct mobile phone number or phone number/n/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>