以文本方式查看主题 - 智睿软件_技术交流论坛 (http://zhirui.net/bbs/index.asp) -- Web程序开发 (http://zhirui.net/bbs/list.asp?boardid=22) ---- ASP用正则验证邮箱地址手机号码电话号码格式 (http://zhirui.net/bbs/dispbbs.asp?boardid=22&id=3646) |
-- 作者:zhirui -- 发布时间:2015-08-19 11:09:38 -- ASP用正则验证邮箱地址手机号码电话号码格式 Function validate(ByVal str,ByVal number) Dim temp,reg Set reg = new regexp reg.ignorecase=true reg.global=true Select Case CStr(number) \' 英文+空格 Case "0" temp = "^[a-zA-Z ]+$" \' 数字+横杠 Case "1" temp = "^[0-9\\-]+$" \' 半角数字 Case "2" temp = "^\\d+$" \' 邮箱地址 Case "3" temp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$" \' 手机号码格式 Case "4" temp = "^(((13[0-9]{1})|159|153)+\\d{8})$" \' 电话号码格式1 Case "5" temp = "^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$" \' 电话号码格式2 Case "6" temp = "^(([0\\+]\\d{2,3}-)?(0\\d{2,3}))?(\\d{7,8})(-(\\d{3,}))?$" Case Else temp = number End Select reg.pattern = temp validate = reg.test(Trim(str)) Set reg = Nothing End Function 条用方法: if validate(tel,4) or validate(tel,5) or validate(tel,6) then else response.Write("<script language=\'javascript\'>alert(\'请检查您的联系电话或者手机号码格式!\'); history.back()</script>") response.End() end if [此贴子已经被作者于2015-08-19 11:10:01编辑过]
|
-- 作者:zhirui -- 发布时间:2015-08-19 11:12:24 -- 随机手机号asp 代码如下: <% Dim m, h, r h = "130,131,138,139" \'号段自己加,保持格式就行 r = split(h, ",") Randomize m = r(Int((UBound(r) + 1) * Rnd)) Do Until Len(m) >= 11 m = m & Int(10000 * Rnd) Loop m = Left(m, 11) Response.Write "手机号:" & m %> \'验证邮箱地址手机号码电话 Function validate(ByVal str,ByVal number) Dim temp,reg Set reg = new regexp reg.ignorecase=true reg.global=true Select Case CStr(number) \' 英文+空格 Case "0" temp = "^[a-zA-Z ]+$" \' 数字+横杠 Case "1" temp = "^[0-9\\-]+$" \' 半角数字 Case "2" temp = "^\\d+$" \' 邮箱地址 Case "3" temp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$" \' 手机号码格式 Case "4" temp = "^(((13[0-9]{1})|159|153)+\\d{8})$" \' 电话号码格式1 Case "5" temp = "^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$" \' 电话号码格式2 Case "6" temp = "^(([0\\+]\\d{2,3}-)?(0\\d{2,3}))?(\\d{7,8})(-(\\d{3,}))?$" Case Else temp = number End Select reg.pattern = temp validate = reg.test(Trim(str)) Set reg = Nothing End Function 条用方法: if validate(tel,4) or validate(tel,5) or validate(tel,6) then else response.Write("<script language=\'javascript\'>alert(\'请检查您的联系电话或者手机号码格式!\'); history.back()</script>") response.End() end if 1、判断字符串是否全是中文 2、判断手机号码长度判断 |
-- 作者:zhirui -- 发布时间:2015-08-27 09:34:23 -- Case "4" temp = "^(13[0-9]|15[012356789]|17[012356789]|18[0-9]|14[57])[0-9]{8}$" |