[英]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.我想在 php 中使用正则表达式,它只允许特定的阿富汗电话代码(+93),之后它可以接受任何其他号码。 How can I do this in php?
我如何在 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
.我试过这个表达式
^(\+|00)[1-9][0-9 \-\(\)\.]{7,}$
但我希望能够接受00937 878 1536
或+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你可以在这里测试它: https://regex101.com/r/6hVHG3/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.