Start Javascript function for validating numbers

Javascript function for validating numbers

When a carrier runs out of one set of numbers – like, sadly, premium-rate – they simply introduce a new prefix.

This will check if the input is a number and it doesn't matter if it is a decimal number or a negative number this function will return true.

When you’re collecting data from users, there are two key challenges; collecting that information, and validating it. In this article I’ll discuss some of the challenges around collecting, validating, and displaying telephone numbers.

The user should select an option other than this ‘Select One’ item.

in Javascript When working with user inputs in web pages it is important that you validate all the inputs, this is so you can check that what the user is entering is the type of data you are expecting.

Then, of course, there was the enormous and unprecedented growth in mobile.

No longer was the number of telephone numbers required largely limited to the number of households, but many times over.

Some types of information are straightforward – someone’s age, for example, couldn’t really be simpler to collect and to validate. Perhaps you’re thinking that since telephone numbers tend to follow a pretty rigid format, such as this: So based on that, we know that the regular expression apparoach isn’t as simple as we first thought – but that’s only the half of it. Sure, if you know that the number you’re collecting is going to be for a specific country, you may be able to use a regular expression. Let’s look at some of the other issues around telephone numbers, and why they make our job even harder.

Names aren’t as straightforward as they sound, but provided you cater for edge cases and international variations – for example patronymics, the mononymous, or even just people with hyphenated surnames – you can’t go too far wrong (although plenty of applications and services do! Email addresses, while theoretically very easy to validate, have their own challenges – yet nevertheless, there are plenty of regular expressions in the wild that aren’t quite right. All sorts of external factors can have implications for telephone numbering.

There wasn't any raw Javascript functions which did what I needed so it was clear that I needed to create my own function to do the job.

After a few searches on some forums and blogs I found a solution which should do exactly what I need from a is_numeric function.

It is important to do both Server and client-side validation, if you just do server side validated then you are putting unnecessary work on the server for a task that can be done on the client side.