Home / Best phone chat portal / Javascript function for validating numbers

Javascript function for validating numbers

The validating phone number is an important point while validating an HTML form.

The check on the length is for a special case involving empty strings.

// Whitespace strings: Is Numeric(' ') == true; Is Numeric('\t\t') == true; Is Numeric('\n\r') == true; // Number literals: Is Numeric(-1) == false; Is Numeric(0) == false; Is Numeric(1.1) == false; Is Numeric(8e5) == false; Arrrgh! Reg Ex is icky for this, and I'm not talking just performance.

It's so easy to make subtle, impossible to spot mistakes with your regular expression.

I can it to work if the input is only digits, but when i type any characters after a number, it will still validate etc.

Unlike many other programming languages, Java Script does not define different types of numbers, like integers, short, long, floating-point etc.

149 comments

  1. Javascript function to validate a. Phone Number validation. The validating phone number is an important point while. Validate North American phone numbers.

  2. Is there is any function like IsNumeric in pure JavaScript? I know jQuery has this function. Is there any function like IsNumeric in JavaScript to validate numbers?

  3. What's the cleanest, most effective way to validate decimal numbers in JavaScript. I want my isNumeric function to consider only Numbers or Strings.

  4. Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, and XML.

Leave a Reply

Your email address will not be published. Required fields are marked *

*