Asp 使用正则 验证数据的有效性

Asp 使用正则 验证数据的有效性

如下所示,自定义函数  CheckExp 用来验证数据的有效性:

'**************************************
'自定义正则表达式 验证数据有效性
'patrn: 表达式
'string: 需要验证的数据
'成功 返回 true
'**************************************
Function CheckExp(patrn, string) 
 REM 建立变量
 Dim regEx, Match
 REM 建立正则表达式 
 Set regEx = New RegExp
 REM 设置模式
 regEx.Pattern = patrn
 REM 设置是否区分字符大小写
 regEx.IgnoreCase = false 
 REM 设置全局可用性
 regEx.Global = True        
 REM 执行搜索
 Matches = regEx.test(string) 

 CheckExp = matches 
End Function 

REM 调用
if CheckExp("^\d{18}$","2013091811ffffd31271163") = true then
    Response.Write "输入正确!"
else
    Response.Write "输入有误!"
end if

你可能感兴趣的:(正则表达式,搜索,regex,asp)