预览模式: 普通 | 列表

ASP下常用正则表达式及字符串验证方法

'常用正则表达式模式
const z_Pat1="^\w+" '匹配有字母,数字,下滑线组成的字符串
const z_PatSW="^[\x00-\xff]+" '匹配所有单字节长度的字符组成的字符串
const z_PatDW="^[^\x00-\xff]+" '匹配所有双字节长度的字符组成的字符串
const z_PatDW2="[^\x00-\xff]+" '字符串是否含有双字节字
const z_PatFileName1="^((\w+)(\.{1})(\w+))" '验证一个文件名,他是由字母,数字,下滑线组成
const z_PatDate1="^19\d{2}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3([0|1])))" '匹配日期(1900-1999)
const z_PatDate2="^20\d{2}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3([0|1])))" '匹配日期(2000-2999)
const z_PatternDateTime="^(1|2\d{3}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3([0|1]))))( (\d{2}):(\d{2}):(\d{2}))?" '匹配日期时间

const z_PatInt="^\d+" '验证整数数字
const z_PatNum="^\d+(\.{1}\d+)?" '数字


'验证指定的字符串是否符合指定的模式
'利用正则表达式
function CheckPattern(str,pat)
set r=new regexp
r.Pattern=pat
r.IgnoreCase=false
r.Global=false
if r.Test(str) then
CheckPattern=true
else
CheckPattern=false
end if
end function

Tags: asp 正则表达式

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3306

 广告位

↑返回顶部↑