javascriptregex

Regex to start with one of three options


I am building a simple form using HTML. I am using Javascript to perform client side validation on the various input fields. One such field is the Phone number field. I am trying to write a Regular Expression that will accept the following:

Currently, I've the following expression: /^\+([0-9])([ .-]*\d){7,20}$/. However this will only accept numbers beginning with +44 rather then numbers beginning with +44 OR 0044 OR 44. My question is how can I modify the above Regular expression in order to check to ensure the number begins with one of the three options?

Many thanks in advance for your help.

Note

A sincere thanks to @melpomene for teaching me the ways of SO and how to struture my questions in an adequate and logical format. I don't know where I'd be today if it weren't for you! :)


Solution

  • ^(?:\+|00)?44[\d\s\-.]*\d$ will match +44, 0044 and 44 followed by any number of either digits, spaces, hyphens or dots. The final \d ensures that the match finishes with a number.