简体   繁体   English

电话号码正则表达式

[英]Phone Number Regular Expression

Basically I am looking for a regular expression for phone numbers.基本上我正在寻找电话号码的正则表达式。

Inputs can be:输入可以是:

009133434343443434
+92333232323232
0223323232
0345*
021*

What I have tried我试过的

^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$

Maximum number of characters in my field can be 20 and least number of fields can be 3 but by the above reg ex i am unable to find appropriate results.我的字段中的最大字符数可以是 20,最少字段数可以是 3,但是通过上面的 reg ex,我无法找到合适的结果。

* can only come in end *只能排在最后
+ can only come at the start of string. +只能出现在字符串的开头。

try to understand regex from this site: http://www.wellho.net/regex/java.html尝试从此站点了解正则表达式: http://www.wellho.net/regex/java.html

check out the regex library here for addresses and phone numbers: http://regexlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7在此处查看正则表达式库以获取地址和电话号码: http://regexlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7

(refresh that last site to get phone number patterns at the beginning.) (刷新最后一个站点以获取开头的电话号码模式。)

I have worked for it and now its working fine for me thanks to All for such a fast response specially saher我已经为它工作了,现在它对我来说工作得很好,这要感谢 All 的如此快速的响应,特别是 saher

^[+ .]?[01]?[01]?\(?[2-9]\d{1,15}\)?[*]*$

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

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