Regular expression for validating phone number
While regular expressions were supported by many UNIX tools for decades, it was only in the last decade or so that they have found their way into most Windows developers' toolkits.
Using regular expressions in Microsoft® Visual Basic® 6 or Microsoft® VBScript was awkward at best, but with the introduction of the . Regular expressions are a language that can be used to explicitly describe patterns within strings of text.
This article covers the basics and recommends where to go to learn more. I hope it will also make a handy reference/refresher for developers who have used regular expressions before, in conjunction with my regular expression cheat sheet.
This article is designed for beginners with little or no experience with regular expressions, but who are familiar with ASP. In this article, I will discuss: If you have questions about this article or regular expressions in general, I invite you to ask them on the regex mailing list at which as I'm writing this has over 350 subscribers.
Below are some sample patterns and inputs they would match.
In addition to specifying that a given pattern may occur exactly 0 or 1 time, the ?
In this case, it would also match the input: The food was quite tasty, which might be not be desired if only a precise match is sought.
Of course, matching exact strings to themselves is a trivial implementation of regular expressions, and doesn't begin to reveal their power.
Now you've gone beyond what literal strings can do (within reason)—it's time to learn some more about regular expressions.Credit for the first regular expressions is given to the mathematician Stephen Kleene.