怎么用正则表达式

来源:百度知道 编辑:UC知道 时间:2024/06/01 14:16:58
我想用正则表达式检验一个变量是否为中文字符,如果不是中文,则弹出一个对话框,帮我写下代码,是asp脚本

匹配一个中文字的正则为:

[\u4e00-\u9fa5]

帮你做了一个测试页:

文件名:test.asp

<%
Function RegExpfind(patrn, strng)
Dim regEx ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全局可用性。
RegExpfind = regEx.Test(strng) ' 执行搜索测试。
End Function

if request("sub")<>"" then
if not RegExpfind("^[\u4e00-\u9fa5]+$", request("str")) then
response.write "<script>alert(""内容不为中文,请重填!"");</script>"
else
response.write "<script>alert(""很成功"");</script>"
end if
end if
%>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="str" val