none
textbox will not accept repeated digits such as the following strings - 0000000, 1111111, 2222222 through 9999999, OR consecutive digits in examples - 1234567, 9876543 RRS feed

  • Question

  • hi,

    i have a scenario with regular expression  

    textbox will not accept repeated digits such as the following strings - 0000000, 1111111, 2222222 through 9999999, OR consecutive digits in these two examples - 1234567, 9876543

    and same text box first two digits entry to be greater than 12 and less than 30 for example 12-xxxxx > or < 30-xxxxx

    how can i develop this regular expression 

    regards

    Rajashekharprvl

    • Moved by CoolDadTx Tuesday, February 27, 2018 8:48 PM Winforms related
    • Moved by Stanly Fan Wednesday, February 28, 2018 2:19 AM
    Monday, February 26, 2018 11:45 PM

All replies

  • What regular expression? What does "will not accept" mean? What happens?


    Sam Hobbs
    SimpleSamples.Info

    Tuesday, February 27, 2018 2:26 AM
  • Hi Maripeddi,

    Thank you for posting here.

    For your question, there is not necessary to use regex.

    Here is a simple way for your reference.

     private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                var ch = textBox1.Text.ToArray();
                if (textBox1.Text.Length >= 1)
                {
                    if (e.KeyChar == Convert.ToChar(ch[textBox1.Text.Length - 1]))
                    {
                        e.Handled = true;
                    }
                    else if (Convert.ToChar(ch[textBox1.Text.Length - 1]) == e.KeyChar - 1 || Convert.ToChar(ch[textBox1.Text.Length - 1] - 1) == e.KeyChar)
                    { 
                        e.Handled = true;
    
                    }
    
                }
    
            }

    Best Regards,

    Wendy


    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.


    Tuesday, February 27, 2018 8:38 AM
  • hi,

    thanks for replay, but my requirement in asp.net mvc. should not accept when user enter a number repeated digits such as the following strings - 0000000, 1111111, 2222222 through 9999999, OR consecutive digits in these two examples - 1234567, 9876543 

    Tuesday, February 27, 2018 10:47 AM
  • In case of exactly seven digits, try this expression:

       ^(?!(?<d>.)(\k<d>){6})(?!1234567|2345678)(1[2-9]|2\d|30)\d{5}$

    If not good, show some examples and give details.



    • Edited by Viorel_MVP Tuesday, February 27, 2018 6:08 PM
    Tuesday, February 27, 2018 6:03 PM
  • hi,

    thanks for replay, but my requirement in asp.net mvc. should not accept when user enter a number repeated digits such as the following strings - 0000000, 1111111, 2222222 through 9999999, OR consecutive digits in these two examples - 1234567, 9876543 

    Hi Maripeddi,

    According to your description, your question is more related to MVC, please post a new thread in MVC forum for suitable support.

    Best Regards,

    Wendy


    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, February 28, 2018 2:17 AM