简体   繁体   中英

Regular expression to allow only specific country telephone code

I would like to use regular expressions in php that allow only specific Afghanistan telephone code which is (+93) and after that it can accept any other number. How can I do this in php?

I have tried this expression ^(\+|00)[1-9][0-9 \-\(\)\.]{7,}$ but I want to be able to accept 00937 878 1536 or +937 878 1536 .

I don't know how to do this with regular expressions.

If it is only for validation purpose, you would test this pattern:

^[\+ 0]0?937 \d{3} \d{4}$

You can test it here: https://regex101.com/r/6hVHG3/1

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM