如何验证只输入文本框中的数字....而不是字母表
问题描述:
亲爱的朋友们,
我正在使用asp.net c#,Sqlserver 2005.
我我的网页上有一个文本框...如何设置该文本框的验证。
我只需输入该文本框中的数字....它不应该拿字母表。
如果用户在该文本框中输入字母...它必须显示一条消息。请输入数字。
请告诉我,
谢谢。
Dear Friends,
am working on asp.net c#, Sqlserver 2005.
I have a textbox on my webpage...How to Set the validation for that Textbox.
I need to enter only numbers in that textbox....it should not take alphabets.
If the user enters alphabets in that textbox...it must show a message. Please enter only numbers.
Please show me,
Thanks.
答
试试这个..
仅接受数字的文本框 [ ^ ]
Try this..
Text box to accept only number[^]
试试这个:
Try this:
void NumberValidation(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 8)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
还可以通过以下链接:
http://techo.luefher .com / coding / javascript-js / how-to-allow-only-numbers-in-html-textbox-using-javascript / [ ^ ]
http://csharpdotnetfreak.blogspot.com/2011/10/numeric- number-only-textbox -javascript.html [ ^ ]
Also go through below link:
http://techo.luefher.com/coding/javascript-js/how-to-allow-only-numbers-in-html-textbox-using-javascript/[^]
http://csharpdotnetfreak.blogspot.com/2011/10/numeric-number-only-textbox-javascript.html[^]