问问题
4230 次
1 回答
2
The following regex will do:
^\+?[0-9\-]+\*?$
How it works:
- Beginning of string:
^
- Optional + character, escaped because "+" could also be a regex operator:
\+?
- At least one character which is either 0-9 or "-", escaped because "-" could also be a regex operator:
[0-9\-]+
- Optional "*" character, escaped:
\*?
- End of string: `$'
Note that this is just a simple example to match the pattern as you defined it. A more elaborate discussion on handling US phone numbers with Regex can be found here
于 2012-11-22T13:36:09.930 回答