none
textbox editting RRS feed

  • Question

  • I have a textbox that holds decimal values(data).

    1 to 10

    I want user to be able to edit with data.

    Check to make sure only period with line.

    Do not allow editing in empty lines.

    How can I do this?

    Tuesday, September 17, 2019 5:32 PM

Answers

  • Hi Jordanhal,

    Thank you for posting here.

    According to you description, you want to do some limits on text inputing.

    You could try the following code to get it.

       private void button1_Click(object sender, EventArgs e)
            {
                string text = textBox1.Text;
                char[] c = { '\n' };
                string[] line = text.Replace('\r',' ').Split(c);
                List<bool> list = new List<bool>();
                foreach (var item in line)
                {
                    bool t = Regex.IsMatch(item.Trim(), "^([0-9]{1,})\\.$")&&(item!=string.Empty);
                    list.Add(t);
                   
                }
                if(list.Contains(false))
                {
                    MessageBox.Show("please enter again");
                }
                else
                {
                    MessageBox.Show("Enter correctly");
                }
            }

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, September 18, 2019 2:35 AM
    Moderator

All replies

  • This forum is for C#-specific questions only. Please identify what UI framework (e.g. Windows Forms, WPF, ASP.NET) you are using so we can move your question to the appropriate forum.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, September 17, 2019 6:03 PM
    Moderator
  • Hi Jordanhal,

    Thank you for posting here.

    According to you description, you want to do some limits on text inputing.

    You could try the following code to get it.

       private void button1_Click(object sender, EventArgs e)
            {
                string text = textBox1.Text;
                char[] c = { '\n' };
                string[] line = text.Replace('\r',' ').Split(c);
                List<bool> list = new List<bool>();
                foreach (var item in line)
                {
                    bool t = Regex.IsMatch(item.Trim(), "^([0-9]{1,})\\.$")&&(item!=string.Empty);
                    list.Add(t);
                   
                }
                if(list.Contains(false))
                {
                    MessageBox.Show("please enter again");
                }
                else
                {
                    MessageBox.Show("Enter correctly");
                }
            }

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, September 18, 2019 2:35 AM
    Moderator