How to detect exact length in regex

前端 未结 8 491
青春惊慌失措
青春惊慌失措 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:21

    Do you mean you want to match up to 10 digits? Try this:

    @"^\s*[0-9]{1,10}\s*$"
    
    0 讨论(0)
  • 2020-12-11 03:25

    Match something non-numeric after the length 10 string. My regex-foo isn't that good, but I think you've got it setup there to catch a numeric string of exactly length 10, but since you don't match anything after that, a length 11 string would also match. Try matching beyond the end of the number and you'll be good.

    0 讨论(0)
提交回复
热议问题