if Regex.IsMatch(ytxt,"^[a-zA-Z]{1}\w{1,7}$") then re="true" else re="false" end if '长度2-8,英文,数字,下化线,首字母必须为英文 这样对了吗
这样是符合你的要求的,不过[a-zA-Z]{1}这里的{1}就没必要了,因为[a-zA-Z]就隐含了一个字母的意思if Regex.IsMatch(ytxt,"^[a-zA-Z]\w{1,7}$") then
但是,我不感觉他运行了啊 好象没有作用啊 我写个“111”他都说是TRUE
断点看下你的,确实是"111"吗?如下代码你试下Dim ytxt As String = "111" If Regex.IsMatch(ytxt, "^[a-zA-Z]\w{1,7}$") Then MessageBox.Show("true") Else MessageBox.Show("false") End If如果你自己测还是不对,那么把你获取源字符串,以及输出结果的代码都贴一下
Sub Page_Load(Src As Object, E As EventArgs) dim ykind as string=request.QueryString("kind") dim ytxt as string =request.QueryString("txt") dim result as string="" dim re as string="true"select case ykind case "id" '检测是不是符合字段规格 '长度2-8,英文,数字,下化线,首字母必须为英文 ytxt="aaa" if Regex.IsMatch(ytxt,"^([a-zA-Z]{1}\w{1,7})$") then re="true" else re="false" end if'检测是不是和数据库中的ID有重复 if re="true" then result=idfinder(ytxt,"id") if trim(result)=trim(ytxt) then re="false" else re="true" END IF end ifend selectresponse.Write(re) End Sub
ytxt="aaa" '这个是你用来做测试的是吧? if Regex.IsMatch(ytxt,"^([a-zA-Z]{1}\w{1,7})$") then re="true" else re="false" end if后面的要根据你的QueryString才能确定结果,但是上面的if判断一定是走re="true"这个分支的这个功能很简单,从头设断点,单步跟踪,看下每一步的判断条件与结果是否相符吧
string str1 = "1233";
string str2 = "1s23s";
string strReg = @"^\d+$";
Response.Write( System.Text.RegularExpressions.Regex.IsMatch( str1 , strReg ) );
Response.Write( "<br />" );
Response.Write( System.Text.RegularExpressions.Regex.IsMatch( str2 , strReg ) );
if (Regex.IsMatch(test, @"^[0-9]+$"))
{
MessageBox.Show("全是数字");
}
else
{
MessageBox.Show("不全是数字");
}
re="true"
else
re="false"
end if
这样写对吗
你可以 return Regex.IsMatch(ytxt,"[a-zA-Z]{1}\w{1,7}")
Regex.IsMatch(ytxt,"[a-zA-Z]{1}\w{1,7}")
的意思是,在你的源字符串里,如果包含如下规律的子串,就re="true",否则re="false"
一个英文字母后接1到7个英文字母或数字,或下划线
re="true"
else
re="false"
end if
'长度2-8,英文,数字,下化线,首字母必须为英文
这样对了吗
好象没有作用啊
我写个“111”他都说是TRUE
If Regex.IsMatch(ytxt, "^[a-zA-Z]\w{1,7}$") Then
MessageBox.Show("true")
Else
MessageBox.Show("false")
End If如果你自己测还是不对,那么把你获取源字符串,以及输出结果的代码都贴一下
dim ykind as string=request.QueryString("kind")
dim ytxt as string =request.QueryString("txt")
dim result as string=""
dim re as string="true"select case ykind
case "id"
'检测是不是符合字段规格
'长度2-8,英文,数字,下化线,首字母必须为英文
ytxt="aaa"
if Regex.IsMatch(ytxt,"^([a-zA-Z]{1}\w{1,7})$") then
re="true"
else
re="false"
end if'检测是不是和数据库中的ID有重复
if re="true" then
result=idfinder(ytxt,"id")
if trim(result)=trim(ytxt) then
re="false"
else
re="true"
END IF
end ifend selectresponse.Write(re)
End Sub
if Regex.IsMatch(ytxt,"^([a-zA-Z]{1}\w{1,7})$") then
re="true"
else
re="false"
end if后面的要根据你的QueryString才能确定结果,但是上面的if判断一定是走re="true"这个分支的这个功能很简单,从头设断点,单步跟踪,看下每一步的判断条件与结果是否相符吧