RegEx 有效的国际手机号码 [英] RegEx for valid international mobile phone number

查看:23
本文介绍了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.

这篇关于RegEx 有效的国际手机号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆