在文本框中仅键入数字和点 [英] type only numbers and dot in textbox
本文介绍了在文本框中仅键入数字和点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我只需要在文本框中输入数字和一个点(.).我如何验证它.我正在用vb使用asp.net.
谢谢
afsal
Hi
I only need to type numbers and one dot(.) in my textbox. how can i validate it. i am using asp.net with vb.
thanks
afsal
推荐答案
尝试以下操作:
Try this:
void NumberValidation(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 46)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
您可以使用ajax控件工具包的Filter文本框扩展程序,也可以使用javascript允许用户仅输入您想要的内容.
You can use Filter textbox extender of ajax control toolkit,or you can use javascript allow user type only what you want.
尝试这个
在textchanged的文本框中验证此功能
try this
in textbox textchanged validate this function
public static bool IsDesimal(string strValue)
{
string decimalNumber = ".0123456789";
for (int i = 0; i < strValue.Trim().Length; i++)
{
if (decimalNumber.IndexOf(strValue[i]) == -1)
{
return false;
}
}
return true;
}
这篇关于在文本框中仅键入数字和点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文