Regular expression for validating phone number in javascript

Everyone must have filled an online form at some stage, a form usually asks for information related to name, phone no, address, credit-card no etc.Incase you didn't provide information in the format specified by the form field or leave it empty, the message will appear and form cannot be submitted until you get it right.So, that was my little hackathon for a couple of weeks, and seems that it succeeded.The resulting library does everything a modern web application needs while maintaining a much smaller size of about 75 Kilo a phone number formatting and parsing library released by Google, originally developed for (and currently used in) Google's Android mobile phone operating system.Implementing a rigorous phone number formatting and parsing library was crucial for the phone OS overall usability (back then, in the early 2000s, it was originally meant to be a phone after all, not just a Snap Chat device). It still can be compiled into one big bundle which weighs 220 Kilo Bytes — quite a size for a phone number input component.Regular expressions can also be used to validate that the input conforms to a given format.

Using this package I created a utility class to validate some commonly used data elements.

About a month ago I decided to begin on the long and tiresome journey of learning regular expressions. So, in this post I’m going to share some of the awesome things I’ve learnt so far on my "journey".

The first thing to note is that I’m no way near the end of my journey and I’m still very much a novice in this area, so if an expert happens to stumble across this post I would very much appreciate some light-hearted critique!

If you’re a novice like me I hope you can gain something from my ramblings.

Most modern programming languages have support for regex (regular expressions) but I’ll be focusing on Java Script’s implementation because that’s what I’m best at!

Regular expression for validating phone number in javascript