智睿软件_技术交流论坛综合站长Web程序开发 → ASP用正则验证邮箱地址手机号码电话号码格式


  共有14508人关注过本帖树形打印

主题:ASP用正则验证邮箱地址手机号码电话号码格式

帅哥哟,离线,有人找我吗?
zhirui
  1楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:520 积分:8740 威望:0 精华:5 注册:2009-07-07
ASP用正则验证邮箱地址手机号码电话号码格式  发帖心情 Post By:2015-08-19 11:09:38

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编辑过]

考试管理系统,适合中小学校,驾校,技术认证考试 支持(1中立(0反对(0回到顶部
帅哥哟,离线,有人找我吗?
zhirui
  2楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:520 积分:8740 威望:0 精华:5 注册:2009-07-07
  发帖心情 Post By: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、判断字符串是否全是中文
注意如果你网页编码是UTF-8,就用我下面的代码,如果是GB2312,就把ACSW改为ACS
function Checkstr(str)
if Len(Hex(Ascw(str)))> 2 Then
Checkstr=true
else
Checkstr=false
end if
End Function
tt="汉字"
if Checkstr(tt)=true then
response.write "字符串为中文"
else
response.write "字符串不是中文"
end if

2、判断手机号码长度判断
function CheckLen(value)
if IsNumeric(value) and len(value)=11 then
CheckLen=True
Else
ChenLen=False
End If
End Function
tt=11223344556
if CheckLen(tt)=true then
response.write "符合要求"
else
response.write "不符合要求"
end if


考试管理系统,适合中小学校,驾校,技术认证考试 支持(1中立(0反对(0回到顶部
帅哥哟,离线,有人找我吗?
zhirui
  3楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:520 积分:8740 威望:0 精华:5 注册:2009-07-07
  发帖心情 Post By:2015-08-27 09:34:23

Case "4" temp = "^(13[0-9]|15[012356789]|17[012356789]|18[0-9]|14[57])[0-9]{8}$"

国际域名60元,空间八折优惠,企业的顶级合作伙伴 支持(1中立(0反对(0回到顶部