如何在c#.net中验证文本框 [英] how to validate text box in c#.net

查看:65
本文介绍了如何在c#.net中验证文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以便文本框只能接受字母

so that a text box can accept only alphabetics

推荐答案

u可以使用f正则表达式^ [a-zA-Z]
u can make use f regular expression ^[a-zA-Z]


....将其与文本框值进行比较....如果在asp中是ur,则可以使用正则表达式验证器工具,或者在后面的代码中首先使用regex属性.
....compare it with the text box value....if u r in asp, u can use regular expression validator tool or else jst use regex property in the code behind.


在page_load事件中添加下划线
textbox.Attributes.Add("onkeypress",返回确保字母Alphabets();");

在aspx页面中添加javascript


函数sureAlphabet()
{var k = window.event.keyCode;
if(!((k& amp; amp; amp; k& 91)||(k& amp; amp; amp; amp; k< 123)|| k == 32 || k == 45 || k == 46))
{window.event.returnValue = false;
}
}
add the belowline in page_load event
textbox.Attributes.Add("onkeypress","return EnsureAlphabets();");

in aspx page add the javascript


function EnsureAlphabet()
{ var k=window.event.keyCode;
if(!((k&gt;64&amp;&amp;k&lt;91)||(k&gt;96&amp;&amp;k&lt;123)||k==32||k==45||k==46))
{ window.event.returnValue=false;
}
}


这篇关于如何在c#.net中验证文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆