/ Published in: Regular Expression
(Created for JavaScript)
These are rather forgiving. Spaces, dashes, or periods are allowed as separators. Extensions can be recognized by several strings (#, x, x., ext, ext., extension).
Area code: $1$2
Exchange code: $3
Station code: $4
Extension / Extra characters: $5
Separators are not accepted within the $3$4$5 portion of a vanity number.
Example: (540) 555-0123 ext.678 --> `($1$2) $3-$4 ext.$5`
Example: 1-800-GOODFOOD --> `1-$1$2-$3$4$5`
These are rather forgiving. Spaces, dashes, or periods are allowed as separators. Extensions can be recognized by several strings (#, x, x., ext, ext., extension).
Area code: $1$2
Exchange code: $3
Station code: $4
Extension / Extra characters: $5
Separators are not accepted within the $3$4$5 portion of a vanity number.
Example: (540) 555-0123 ext.678 --> `($1$2) $3-$4 ext.$5`
Example: 1-800-GOODFOOD --> `1-$1$2-$3$4$5`
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//10-digit phone number ^(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$ //10-digit phone number, extension allowed ^(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$ //7 or 10-digit phone number ^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$ //7 or 10-digit phone number, extension allowed ^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$ //10-digit phone number, vanity (alphanumeric) allowed ^(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9a-z]1[02-9a-z]|[2-9a-z][02-9a-z]1|[2-9a-z][02-9a-z]{2})([0-9a-z]{4})$ //10-digit phone number, vanity allowed, extra characters allowed at end ^(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9a-z]1[02-9a-z]|[2-9a-z][02-9a-z]1|[2-9a-z][02-9a-z]{2})([0-9a-z]{4})([0-9a-z]*)$
URL: http://en.wikipedia.org/wiki/North_American_Numbering_Plan