问题描述
我使用Clickatell将SMS发送到客户的手机.
I use Clickatell to send SMSes to clients' mobile phones.
是否为所有有效的手机号码(例如)提供了标准化的正则表达式+27 123 4567?我会自己动手,但我担心会丢失晦涩,有效的电话号码格式.
Is there a standardised regular expression for all valid mobile phone numbers, e.g. +27 123 4567? I'd roll my own, but I'm worried about missing an obscure, valid phone number format.
推荐答案
从输入中去除除'+'和数字以外的所有字符后,应该这样做:
After stripping all characters except '+' and digits from your input, this should do it:
^\+[1-9]{1}[0-9]{3,14}$
如果您想更准确地使用国家/地区代码,请在电话号码国家/地区代码
If you want to be more exact with the country codes see this question on List of phone number country codes
但是,我会尽量不严格要求我进行验证.如果告知用户有效数字不可接受,他们会感到非常沮丧.
However, I would try to be not too strict with my validation. Users get very frustrated if they are told their valid numbers are not acceptable.
这篇关于正则表达式以获取有效的国际手机号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!