Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, your format validator is obviously only appropriate for <a href="http://en.wikipedia.org/wiki/North_American_Numbering_Plan" rel="noreferrer">NANP</a> (country code +1) numbers. Will your application be used by someone with a phone number from outside North America? If so, you don't want to prevent those people from entering a perfectly valid [international] number.</p> <p>Secondly, your validation is incorrect. NANP numbers take the form <code>NXX NXX XXXX</code> where <code>N</code> is a digit 2-9 and <code>X</code> is a digit 0-9. Additionally, area codes and exchanges may not take the form <code>N11</code> (end with two ones) to avoid confusion with special services <em>except</em> numbers in a non-geographic area code (800, 888, 877, 866, 855, 900) may have a <code>N11</code> exchange.</p> <p>So, your regex will pass the number (123) 123 4566 even though that is not a valid phone number. You can fix that by replacing <code>\d{3}</code> with <code>[2-9]{1}\d{2}</code>.</p> <p>Finally, I get the feeling you're validating user input in a web browser. Remember that client-side validation is <a href="https://stackoverflow.com/questions/1726617/form-validation-with-javascript-vs-php">only a <strong>convenience</strong> you provide to the user</a>; you still need to validate all input (again) on the server.</p> <p><strong>TL;DR</strong> don't use a regular expression to <a href="https://stackoverflow.com/a/5059082/1269037">validate complex real-world data like phone numbers</a> or <a href="https://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links/21925491#21925491">URLs</a>. Use a <a href="https://github.com/googlei18n/libphonenumber" rel="noreferrer">specialized library</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload