How to detect exact length in regex

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

    This should match only 10 digits and allow arbitrary numbers of whitespaces before and after the digits.

    Non-capturing version: (only matches, the matched digits are not stored)

    ^\s*(?:\d{10})\s*$
    

    Capturing version: (the matched digits are available in subgroup 1, as $1 or \1)

    ^\s*(\d{10})\s*$
    

提交回复
热议问题