Everyone knows that a credit card number is normally made up of 12-16 numbers.

However there are many ways that people type their number into a form, often including spaces or hyphens to break up the number and make it more readable.

In the ECMAScript specification, they only exist conceptually: All numbers are always floating point and integers are ranges of numbers without decimal fractions (for details, consult “Integers in Java Script” in “Speaking Java Script”).

javascript code for validating numbers-19

Javascript code for validating numbers video

Here user can enter either phone number or mobile number. Here user can enter either 10 digit number(which starts from 9) OR can enter 8 digit number(starts with 2).

This function first determines the ASCII code of the keyboard key and then verifies that its ASCII code is within the range 48 to 57.

Also it makes sure that the key pressed is not an special key like Backspace or Delete, if yes then that too is excluded Hi, This is Mudassar Khan. Net Question Answer site, specially started to allow visitors of this site ask their doubts and queries. Just click the Ask Now button and ask your question now.

Now you can ask questions directly to me on my new site ASPForums.

Remember it is always necessary to validate form input values using a server-side script to cater for non-Java Script browsers or exploit attempts.

This example goes one step futher and also checks that the number entered is valid according to the Luhn algorithm (also known as the "mod 10" algorithm).PI); // false Integer(Na N); // false Integer(Infinity); // false Integer(-Infinity); // false Integer('10'); // false Integer(true); // false Integer(false); // false Integer([1]); // false The compatibility table in this page is generated from structured data.If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.This requires an extra Java Script function that implements the Luhn algorithm: For the logic and history behind the algorithm see the link above.Basically it's a method used by credit card companies for decades now to detect errors in card numbers without having to look up the actual account.The following Javascript uses the test() method tests for a match in a string.