如何检查文本框是否包含C#中的小数点 [英] how to check whether a textbox contains a decimal point in the starting in C#

查看:152
本文介绍了如何检查文本框是否包含C#中的小数点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个接受小时的文本框。它只允许数字和小数点。最多只允许一个小数点。



因此,当用户在文本框的开头输入单个小数点而没有任何其他数字时,单击确定时应显示警告消息。



如何在C#中实现?

Hi,

I have a text box which accepts hours.It will allow only numeric and decimal points.And max of only single decimal point is allowed.

So when the user enters single decimal point in the starting of the textbox without any other digits, and on click of Ok an alert message should be displayed.

How can i achieve that in C#?

推荐答案

如果您只检查用户输入是否有效点击OK,尝试这样的事情:

If you are only checking if the input is valid when the user clicks OK, try something like this:
double userinput = 0;
bool isvalid = double.TryParse(yourtextbox.text, out userinput);
if (!isvalid)
{
   MessageBox.Show("Invalid Entry"); //Etc.
}
else
{
   MessageBox.Show("You entered: " + userinput.ToString());
}





希望这会有所帮助: - )



Hope this helps :-)


这篇关于如何检查文本框是否包含C#中的小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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