How to Validation phone number and -

前端 未结 5 2066
星月不相逢
星月不相逢 2021-01-14 23:26

For the validation for the phone number and included -

@\"^\\+(?:[0-9] ?){6,14}[0-9]$\"

I have to validate phone number with -

example 333-333-3333 (

5条回答
  •  悲&欢浪女
    2021-01-15 00:24

    well it depends on how strict you want to be it doesn't seem like this regex is especially strict. this regex says:

    1. start at beginning of line
    2. match one + (or maybe 1 or 0) which seems ambiguous (but may not be depending on implementation) because the capture parentheses:() breaks up the relationship of the \+ and the ?
    3. possibly misplaced :
    4. match any digit 0-9 1 or 0 times 6-14 times
    5. then one digit 0-9
    6. then end of line.

    also you note that any backslash will have to be doubled... @"\\b" for a word boundary. you may want to try something like...

    @"\\b[\\d]{3}\\-[\\d]{3}\\-[\\d]{4}\\b"
    would I think match your example, but it wouldn't match
    (555) 555 - 5555 or
    555.555.5555 or
    +44 1865  55555
    

提交回复
热议问题