RegEx 有效的国际手机号码

问题描述:

我使用 Clickatell 向客户的手机发送短信.

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.