Currently, I have this regex for telephone number
/^\+?\d+(-\d+)*$/
which allows:
123
123-456
123-456-789
I'm aiming to also accept parenthesis in my regex ( ) for example:
(02)123-456
How can I do it with my current regex?
Add/Append (\\(\\d+\\))?
in front of /^\\+?\\d+(-\\d+)*$/
If you need min. 2 numbers, use this (\\(\\d{2,}\\))?
Basically, you need to escape the ()
, remember that in almost any language you would do it with the \\
-character. From then on you only need to specify the number of occurrences.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.