当前位置: 代码迷 >> ASP.NET >> textbox里面 怎么限制只能输入字符或数字,禁止输入汉字,
  详细解决方案

textbox里面 怎么限制只能输入字符或数字,禁止输入汉字,

热度:4810   发布时间:2013-02-25 00:00:00.0
textbox里面 如何限制只能输入字符或数字,禁止输入汉字,!
如题!

------解决方案--------------------------------------------------------
验证控件

js判断

ascall码判断


------解决方案--------------------------------------------------------
<asp:RegularExpressionValidator ID= "RegularExpressionValidator1 " runat= "server " ErrorMessage= "Invalid username or password " ControlToValidate= "textbox1 " ValidationExpression= "^[A-Za-z]+\w+$ " Display= "None "> * </asp:RegularExpressionValidator>
------解决方案--------------------------------------------------------
try:

<asp:TextBox id= "t1 " runat= "server " style= "ime-mode:disabled; " />


------解决方案--------------------------------------------------------
结分阿
------解决方案--------------------------------------------------------
用正则表达式+JS判断
正则:^[A-Za-z0-9]+$

------解决方案--------------------------------------------------------
/**
*校验字符串是否为空
*返回值:
*如果不为空,定义校验通过,返回true
*如果为空,校验不通过,返回false 参考提示信息:输入域不能为空!
*/
function checkIsNotEmpty(str)
{
if(str.trim() == " ")
return false;
else
return true;
}//~~~
/*--------------------------------- Empty --------------------------------------*/
/********************************** Integer *************************************/
/**
*校验字符串是否为整型
*返回值:
*如果为空,定义校验通过, 返回true
*如果字串全部为数字,校验通过,返回true
*如果校验不通过, 返回false 参考提示信息:输入域必须为数字!
*/
function checkIsInteger(str)
{
//如果为空,则通过校验
if(str == " ")
return true;
if(/^(\\-?)(\\d+)$/.test(str))
return true;
else
return false;
}//~~~
*/
------解决方案--------------------------------------------------------
网上一搜就有。
------解决方案--------------------------------------------------------
regular is easy.
------解决方案--------------------------------------------------------
如题!
------解决方案--------------------------------------------------------
正则
------解决方案--------------------------------------------------------
<asp:TextBox id= "TextBox1 " runat= "server " style= "IME-MODE:disabled; " />
  相关解决方案