Validating a number

Luckily for developers there is an unambiguous, internationally recognized standard for telephone numbers anywhere in the World called E.164.

The format is broken down as follows: We can represent any valid telephone number using the E.164 format.

The continued strain on the pool of available numbers can only increase the likelihood of further changes.

Registration is required through our Business Services Online Welcome page.Third-party preparers need only register once in their own firm's name.When a carrier runs out of one set of numbers – like, sadly, premium-rate – they simply introduce a new prefix.Some changes have enormous implications; in the United Kingdom some years ago, for example, the entire regional numbering system underwent a drastic change, with virtually every area code getting an additional “1” inserted.We can look up the countries which use a particular dialing code: /** * Gets the dialing codes for a given country * * @param string country The two-character country code * @return array An array of strings representing the dialing codes */ get Codes : function(country) You’ll find these functions packaged up as a module, along with unit tests, in the repository that accompanies the article.

Even international dialing codes, however, aren’t as straightforward as you may think.

First, virtually no one would type or read out their number in that format. Later though, when we look at , we’ll see that there are ways of formatting numbers for humans.

First though, let’s look at the issue of collecting telephone numbers. However, because of the issues around the variations in format, it doesn’t actually place any restrictions on what the user can type, nor does it perform any validation in the same way as, say, the email element.

Here is an excerpt from As you can see, this demonstrates that Austria uses the international dialing code 43. Well, using the magic of Lodash (or Underscore), there are a few ways in which we can query dialing code-related information.

For example, to find out whether a given dialing code is valid: There are a more efficent ways of doing this, of course, so this and the following examples aren’t necessarily optimized for production.

But for anything remotely automated – such as sending SMS messages – or to validate them effectively, you’ll need to capture the country prefix.