There's no difference between phone and fax numbers. To make a regular expression, you'd have to ask yourself a couple of questions:
- Do you require an area code, or will 7 digits be acceptable? Do you want to validate the area code as well?
- In the US, it's not uncommon to use letters instead of digits. Is your regexp going to allow that?
- Do you insist on separators? Are the optional? Forbidden? If they are separators, can they be dashes? Spaces? Either, but not mixed? Allowed elsewhere than the standard 3-3-4 grouping? Can you have parenthesis around the area code?
- Do you require a leading 1? Is it optional? Do you allow the international '+' prefix?
- What about extensions? Allowed? If so, for how many numbers?
- It's possible to hook in a fax into a 911 dispatch center, making it a 'fax number' as well. Are you going to allow that as well?
Depending on the answers, your regexp can be as simple as /1[0-9]{10}/, or something far more complex.
1-800-JAVA-FAN
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|