title: Regular expression to match standard 10 digit phone number
body: <p>I want to write a regular expression for a standard US type phone number that supports the following formats:</p>
  
  <pre><code>###-###-####
  (###) ###-####
  ### ### ####
  ###.###.####
  </code></pre>
  
  <p>where # means any number. So far I came up with the following expressions</p>
  
  <pre><code>^[1-9]\d{2}-\d{3}-\d{4}
  ^\(\d{3}\)\s\d{3}-\d{4}
  ^[1-9]\d{2}\s\d{3}\s\d{4}
  ^[1-9]\d{2}\.\d{3}\.\d{4}
  </code></pre>
  
  <p>respectively. I am not quite sure if the last one is correct for the dotted check. I also want to know if there is any way I could write a single expression instead of the 4 different ones that cater to the different formats I mentioned. If so, I am not sure how do I do that. And also how do I modify the expression/expressions so that I can also include a condition to support the area code as optional component. Something like</p>
  
  <pre><code>+1 ### ### ####
  </code></pre>
  
  <p>where +1 is the area code and it is optional.</p>