求手机号码正则表达式

javascript如何去验证输入的手机号码必须是正确的呢?正则表达式该如何去写,需要是比较完整的验证。。急!

JavaSript中手机正则表达式:
function isMobil(s)
{
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
另外都通用滴:
联通:^0?13[0-3]\d{8}$
移动:^0?13[4-9]\d{8}$
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-07-13
<script LANGUAGE="JavaScript">

<!--

function checkMobile(){

var sMobile = document.mobileform.mobile.value

if(!(/^1[3|5][0-9]\d{4,8}$/.test(sMobile))){

alert("不是完整的11位手机号或者正确的手机号前七位");

document.mobileform.mobile.focus();

return false;

}

}

//-->

</script>本回答被网友采纳
第2个回答  2013-07-13
var tel_num = /1[35]\d{9}/;
if(!tel_num.test(document.myform.tel.value))
alert("手机号码格式错误");
第3个回答  2013-07-13
完整版:
#####函数代码########
假设为myfunc.asp

<%
'正则表表达式验证函数 patrn-正则表达式 strng-需要验证的字符串
Function RegExpTest(patrn, strng)
Dim regEx, retVal ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = False ' 设置是否区分大小写。
retVal = regEx.Test(strng) ' 执行搜索测试。
RegExpTest = retVal '返回不尔值,不符合就返回false,符合为true
End Function
%>

#####提交页面代码######
假设为mypage.asp

<form method="post" action="check.asp">
请输入E-mail地址:<input type=text name=email>
<br>
请输入电话号码:<input type=text name=tel>
<input type=submit value="确定">
</form>

#####验证页面########
假设为check.asp

<!--#include file="myfunc.asp"-->
<%
tel=request.form("tel")
email=request.form("email")
dim founderr : founderr=false '建立变量,正确或者失败标记
'大家注意哦,顺便我在这里贡献一个正则表达式,同时验证电话号码和手机号码的!
if RegExpTest("(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)", tel)=false then
founderr=true
regshow=regshow&"<li>您输入的电话号码格式不正确"
end if
if RegExpTest("^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$", email)=false then
founderr=true
regshow=regshow&"<li>您输入的电子邮箱格式不正确"
end if
if founderr=false then regshow="<li>您输入的格式都是正确的哦"
%>
<br><br>
<%=regshow%>

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网