How to detect exact length in regex

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

    If you are trying to match only numbers that are 10 digits long, just add a trailing anchor using $, like this:

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

    That will match any number that is exactly 10 digits long (with optional space on either side).

提交回复
热议问题