[英]Regex for valid phone numbers
I'am having some issues creating a regex to validate phone numbers. 我在创建用于验证电话号码的正则表达式时遇到了一些问题。 The validations that i need is the following:
我需要的验证如下:
has either 3 digits or between 7 and 12 digits (inclusive) - can have the optional '+' character in the beginning (before any digit) - can start with '00', in which case it shouldn't start with the '+' sign - if it starts with '00', these two digits don't count to the maximum number of digits - cannot have any letters - cannot have any symbol aside from the beginning '+' sign - cannot have any whitespace between the '+' sign and the first digit but can have any amount of whitespace in all other places 可以是3位数字,也可以是7到12位数字(含)之间-开头可以有可选的“ +”字符(在任何数字之前)-可以以“ 00”开头,在这种情况下,不应以“ +”开头'符号-如果以'00'开头,则这两位数字不会计入最大位数-不能有任何字母-除'+'开头不能有任何符号-在'之间不能有空格+'号和第一个数字,但在所有其他位置可以有任意数量的空格
What I have is the following -> ^[+]{0,1}[-\\s/0-9]*$
我所拥有的是以下->
^[+]{0,1}[-\\s/0-9]*$
I'd go with this: 我会这样:
^(\+|00)?(\d\s*){7,12}$
^
start of the string ^
字符串的开头 (\\+|00)?
optional + or 00 (\\d\\s*){7,12}
a digit followed by zero or more spaces, 7 to 12 times (\\d\\s*){7,12}
一个数字,后跟零个或多个空格,为7到12次 $
end of string $
字符串结尾
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.