我是用C#的,在实现用户注册的时候我想实现在点击提交按钮的时候如果发现用户名的TextBox中有非法字符,就弹出对话框提示,请问怎么才能发现有非法字符呢?不知道代码怎么写?希望大家能帮帮我,谢谢
------解决方案--------------------------------------------------------
//验证一般用户名字符和数字是否再8至12个之间
public static bool IsValidByte(string strIn)
{
return Regex.IsMatch(strIn, @ "^[\w]{8,12}$ ");
}
------解决方案--------------------------------------------------------
加验证 就是楼上说的 然后根据验证结果再判断
------解决方案--------------------------------------------------------
用RegularExpressionValidator正则验证控件:
<ASP:RegularExpressionValidator id= "Validator_ID " RunAt= "Server "
ControlToValidate= "你的Textbox "
ValidationExpression= "^[\w]{8,12}$ "
errorMessage= "错误信息 "
display= "Static "
>
http://hi.baidu.com/sujun/blog/item/2e825aee1c1c47fab2fb95e3
------解决方案--------------------------------------------------------
如是要验证非法字符,改下正则就行了:
<ASP:RegularExpressionValidator id= "Validator_ID " RunAt= "Server "
ControlToValidate= "你的Textbox的id "
ValidationExpression= "^[a|b|c]$ "
errorMessage= "错误信息 "
display= "Static "
>
上面假设a,b,c为非法字符
------解决方案--------------------------------------------------------
上面的方法都可以,如果你想做弹出窗口,就用javascript吧,