如何在C#中启动时检查文本框是否包含小数点 [英] How Can I Check Whether A Textbox Contains A Decimal Point In The Starting In C#

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

问题描述





我有一个只接受数字和小数点的文本框。那么当C#中单击OK按钮时文本框只包含一个没有任何数值的小数点时,如何显示警告信息?

Hi,

i have a text box which accepts only numeric and decimal points. so how can i display an alert message when a textbox only contains a decimal point without any numeric value on click of OK button in C#?

推荐答案

if (TextBox1.Text.Split('.').Length > 1)
{    // alert message for multiple dots
}
           if (TextBox1.Text.Trim() == ".")
           {
               // alert message for only dot
           }


尝试:

Try:
if (myTextBox.Text.Trim() == ".")
   {
   ...
   }


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Regex r1 = new Regex(@"^.


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

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