开发者

Java regex for a specific phone number format

I am looking for a regex java pattern to match the following string:

 [Phone Number]= 1234567890

Here: The regex should look for hardcoded string of "[Phone Num开发者_JS百科ber]=" followed by space or not, and followed by any numbers of digits.

That means it should match:

[Phone Number]= 123456 and
[Phone Number]=1234567890

Any help is appreciated.


Well, something like:

String pattern = "\\[Phone Number\\]= ?\\d+";
  • The backslashes are doubled just because of Java string literal syntax
  • The square brackets are escaped to avoid them being used to group a set of characters
  • The ? means zero or one space
  • The \d+ (after unescaping) means "at least one digit"


What are your rules for a phone number? Simply a list of digits is rarely a valid phone number format.

A simple search can find you the regexps for specific countries (I'll provide a specific one if you can tell us which one you need).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜