Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
^([0-9]{2,3})([\s.-]?)([0-9]{3,4})([\s.-]?)([0-9]{4})$
/
gm

Description

  • Rules for Mexico:
  1. Numbers must be 10 digits long
  2. Area code is either 2 or 3 digits
  3. Remaining phone number has either 7 or 8 digits in groups of 3 or 4
Submitted by anonymous - 4 years ago