none
regex for two characters only RRS feed

Answers

  • Hello arkiboys,

    Try the following code:

     string s1 = "2r";
      
     string regex1 = @"^[A-Za-z0-9]{2}$";
    
     Boolean isValild1 = Regex.IsMatch(s1, regex1);

    Sincerely,

    Neil Hu


    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.

    Thursday, November 16, 2017 9:24 AM
    Moderator

All replies

  • When you want to limit the # of characters to an exact amount you use the {2} syntax.

    var pattern = "\w{2}";


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, November 15, 2017 2:59 PM
    Moderator
  • Hello arkiboys,

    Try the following code:

     string s1 = "2r";
      
     string regex1 = @"^[A-Za-z0-9]{2}$";
    
     Boolean isValild1 = Regex.IsMatch(s1, regex1);

    Sincerely,

    Neil Hu


    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.

    Thursday, November 16, 2017 9:24 AM
    Moderator
  • Hello arkiboys,

    Did you have anything to update?  If you already have got the useful solution from there, you could close the thread by marking the useful reply  as answer, This can be beneficial to other community members reading this thread. Thanks a lot.

    Sincerely,
    Neil Hu


    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.

    Sunday, November 26, 2017 11:51 AM
    Moderator