[基础]电话/手机常见验证的Javascript示例
来源:互联网 发布:c语言如何模块化 编辑:程序博客网 时间:2024/06/10 15:02
电话号码:<input type="text" id="TelPrefix" size="4" MaxLength="4"> - <input type="text" id="TelNumber" style="width:88px"> <button id="btnTestTel" onClick="return TestTel()">测试电话号码</button><br/>
手机号码:<input type="text" id="Mobile"> <button id="btnTestMobile" onClick="return TestMobile()">测试手机号码</button><br/><br/>
建议手机号码与电话号码至少请输入一项<br/><br/>
<button id="btnTest" onClick="return Test()">测试手机号码</button>
<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 (/^(?:13d|15[89])-?d...{5}(d...{3}|*...{3})$/.test(this.Trim()));
}
String.prototype.isTel = function()
...{
return (/^(([0+]d...{2,3}-)?(0d...{2,3})-)(d...{7,8})(-(d...{3,}))?$/.test(this.Trim()));
}
function TestMobile()
...{
var oMobile = document.getElementById("Mobile");
if (!oMobile.value.isMobile())
...{
alert("请输入正确的手机号码");
oMobile.focus();
oMobile.style.backgroundColor="#ff9";
return false;
}
else
...{
alert(oMobile.value);
}
return true;
}
function TestMobileEx()
...{
var oMobile = document.getElementById("Mobile");
if (!oMobile.value.isMobile())
...{
return false;
}
return true;
}
function TestTel()
...{
var oTelPrefix = document.getElementById("TelPrefix");
var oTelNumber = document.getElementById("TelNumber");
var sTel = oTelPrefix.value + "-" + oTelNumber.value;
if (!sTel.isTel())
...{
alert("请输入正确的电话号码");
oTelPrefix.focus();
oTelPrefix.style.backgroundColor="#ff9";
oTelNumber.style.backgroundColor="#ff9";
return false;
}
else
...{
alert(sTel);
}
return true;
}
function TestTelEx()
...{
var oTelPrefix = document.getElementById("TelPrefix");
var oTelNumber = document.getElementById("TelNumber");
var sTel = oTelPrefix.value + "-" + oTelNumber.value;
if (!sTel.isTel())
...{
return false;
}
return true;
}
function Test()
...{
if (TestTelEx()||TestMobileEx())
...{
alert("验证通过");
}
else
...{
alert("手机,电话至少输入一项");
document.getElementById("TelPrefix").focus();
document.getElementById("TelPrefix").style.backgroundColor="#ff9";
return false;
}
return true;
}
</script>
手机号码:<input type="text" id="Mobile"> <button id="btnTestMobile" onClick="return TestMobile()">测试手机号码</button><br/><br/>
建议手机号码与电话号码至少请输入一项<br/><br/>
<button id="btnTest" onClick="return Test()">测试手机号码</button>
<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 (/^(?:13d|15[89])-?d...{5}(d...{3}|*...{3})$/.test(this.Trim()));
}
String.prototype.isTel = function()
...{
return (/^(([0+]d...{2,3}-)?(0d...{2,3})-)(d...{7,8})(-(d...{3,}))?$/.test(this.Trim()));
}
function TestMobile()
...{
var oMobile = document.getElementById("Mobile");
if (!oMobile.value.isMobile())
...{
alert("请输入正确的手机号码");
oMobile.focus();
oMobile.style.backgroundColor="#ff9";
return false;
}
else
...{
alert(oMobile.value);
}
return true;
}
function TestMobileEx()
...{
var oMobile = document.getElementById("Mobile");
if (!oMobile.value.isMobile())
...{
return false;
}
return true;
}
function TestTel()
...{
var oTelPrefix = document.getElementById("TelPrefix");
var oTelNumber = document.getElementById("TelNumber");
var sTel = oTelPrefix.value + "-" + oTelNumber.value;
if (!sTel.isTel())
...{
alert("请输入正确的电话号码");
oTelPrefix.focus();
oTelPrefix.style.backgroundColor="#ff9";
oTelNumber.style.backgroundColor="#ff9";
return false;
}
else
...{
alert(sTel);
}
return true;
}
function TestTelEx()
...{
var oTelPrefix = document.getElementById("TelPrefix");
var oTelNumber = document.getElementById("TelNumber");
var sTel = oTelPrefix.value + "-" + oTelNumber.value;
if (!sTel.isTel())
...{
return false;
}
return true;
}
function Test()
...{
if (TestTelEx()||TestMobileEx())
...{
alert("验证通过");
}
else
...{
alert("手机,电话至少输入一项");
document.getElementById("TelPrefix").focus();
document.getElementById("TelPrefix").style.backgroundColor="#ff9";
return false;
}
return true;
}
</script>
- [基础]电话/手机常见验证的Javascript示例
- 手机和电话的验证
- Javascript验证电话、邮编、手机实例
- js手机电话验证
- C#验证国内电话和手机的正则表达式
- 正则表达式---手机,邮箱,固定电话格式的验证
- jq 通过正则表达式实现邮箱手机电话的验证
- javascript 电话,QQ,手机,身份证号,邮箱地址,邮政 正则表达式验证代码
- javascript:验证邮箱、电话、QQ的正则表达式
- JavaScript里的手机邮箱验证
- 正则表达式 验证 电话,手机,邮箱,数字
- 固定电话、传真和手机js验证
- js验证邮箱,固定电话,手机等
- 通用JS验证(手机,电话,邮箱,QQ)
- JS/JQuery 邮箱 手机 电话 正则验证
- JavaScript表单验证示例
- javascript中的常见验证
- javascript常见验证
- 通过网页链接打开应用程序客户端的两种实现方式
- event.button 含义
- VB.NET中字符串操作函数
- 每日来一句英语1
- C#中字段与属性性能比较
- [基础]电话/手机常见验证的Javascript示例
- c#,递归,下载文件夹的全部内容
- SWT中的FormLayout
- 李彦宏揭秘:百度为什么推出自己的网站
- 如何更改workspace(工作空间)的目录名?
- 做网站技巧
- asp.net(c#) 制作注册码程序
- CPU的数据、地址、控制总路线
- DOS经典