How to detect exact length in regex

前端 未结 8 531
青春惊慌失措
青春惊慌失措 2020-12-11 02:42

I have two regular expressions that validate the values entered.

One that allows any length of Alpha-Numeric value:

@\"^\\s*(?[A-Z0-9]+)         


        
8条回答
  •  粉色の甜心
    2020-12-11 03:03

    I think what you're trying to say is that you don't want to allow any more than 10 digits. So, just add a $ at the end to specify the end of the regex.

    Example: @"^\s*(?[0-9]{10})$"


    Here's my original answer, but I think I read you too exact.

    string myRegexString = `@"(?!(^\d{11}$)` ... your regex here ... )";
    

    That reads "while ahead is not, start, 11 digits, end"

提交回复
热议问题