简体   繁体   English

Codeigniter中电话号码的正则表达式

[英]Regular expression for phone number in codeigniter

I am using codeigniter and I want to check user input with regular expression for phone number. 我正在使用codeigniter,我想用正则表达式检查用户输入的电话号码。 My pattern is [+]zero or one and [0-9] number. 我的模式是[+]零或一和[0-9]数字。
Following format, 按照以下格式,
+959250142935 959250142935
09250142935 09250142935
This is my pattern - /\\+?[0-9]$/ 这是我的模式-/ \\ +?[0-9] $ /
This does not work as I expected. 这不符合我的预期。

You can use the following pattern to check for valid phone number. 您可以使用以下模式检查有效的电话号码。 There is a additional {5,} to set a minimum length of the phone number (in this case 5), so the phone number can't be a single number: 还有一个附加的{5,}来设置电话号码的最小长度(在这种情况下为5),因此电话号码不能是一个数字:

^[\\+]{0,1}[0-9]{5,}$ or ^[\\+]{0,1}\\d{5,}$ ^[\\+]{0,1}[0-9]{5,}$^[\\+]{0,1}\\d{5,}$

You can use this pattern directly on the <input> : 您可以直接在<input>上使用此模式:

<input pattern="^[\+]{0,1}[0-9]{5,}$" type="text"/>
<input pattern="^[\+]{0,1}\d{5,}$" type="text"/>

Try with this regex 尝试使用此正则表达式

/^(\\+|0|1)\\d+$/

If the number must be certaing length 如果数量一定要确定长度

/^(\\+|0|1)\\d{10}$/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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