且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中启动时检查文本框是否包含小数点

更新时间:2023-11-28 16:50:58

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(@"^.