Regex that allows mobile numbers starting with * or #
I need a regex that matches a mobile phone number(with a maximum of 9 digits) starting with * or # , like these ones:
#964418878
*8745858
*98568开发者_运维技巧6869
Hope you can help me out
The following should do what you want:
/^[*#]\d{1,9}$/
This assume your strings ONLY consist of the phone numbers, one per string. If you're just checking that they exist in a larger string, remove the ^
and $
characters.
Just nine consecutive digits?
^(\*|#)\d{1,9}$
Replace 1
with the minimum number of digits you want to have.
This is a good place to start learning regular expressions: http://www.regular-expressions.info/
Something like this, depending on the regex flavor:
/[#*]?\d{1,9}/
\d
is an alias for [0-9]
, so if the former isn't supported on your platform (is there such a beast?) then use the latter. Also, this is the syntax for a find, if you want a match, add ^
and $
to beginning and end, respectively.
精彩评论