开发者

Simple phone regex

I w开发者_如何学Cant a regex that checks the following things:

  1. The string starts with an +
  2. After the '+' only numbers can occur
  3. There should be atleast 4 numbers after the +

Does anyone know how to make this?


/^+\d{4,}$/

will meet your requirements.

^ is the anchor for start fo the string

\d is a digit

{4,} says at least 4 of the preceding expression (here the \d). you can add a maximum if needed like {4,20} would allow at least 4 and at most 20 characters.

$ is the anchor for the end of the string


/^((00|\+)[0-9]{2,3}){0,1}[0-9]{4,14}$/

More general than your request, but you can specialize it. Explaining:

((00|\+)[0-9]{2,3}) 

international code with 00 or + and 2 or 3 digits. Modify the expression according to your needs.

 {0,1} 

international code is optional - remove it if it is required

[0-9]{4,14} 

digits: minimum 4, maximum 14. Change the values according to your needs.

Regards A.


/\+\d{4,15}/

This should help if 15 is the atmost limit of numbers

OR rather keep the second parameter blank as stema suggested.


I went with this one:

/\A(([+]\d{3,})?\d{6,8})/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜