Javascript isNumber / isNumeric function

Script version:1.1
Language:Javascript
Rating:
4 (1 votes cast)
Category:13
Description:This function checks whether an inputted value is a number or not. There are 3 parameters:

the first is the string to check, - accepts a string value - this parameter is mandatory

the second optional parameter tells the function whether to include non whole numbers, accepts either true or false (true means that decimal points are accepted

the third optional parameter tells the function whether to include negative numbers, accepts true or false (true means that negative numbers are valid

[note, this script was updated on 16/11/09 to correct the case error in the last line of code.
Instructions:Example call to the function as follows:

alert(isNumeric('12345')) // - returns true

alert(isNumeric('-12345')) // returns false

alert(isNumeric('-12345',true,true)) // returns true

alert(isNumeric('12E45')) // returns false

alert(isNumeric('0.12345',false)) // returns false



alert(isNumeric('0.12345',true)) // returns true




Code:




Comments

Name: *
Email: (not shown on website)
Website:
Rate this script:
1 2 3 4 5 6 7 8 9 10
worse better
Comment: *
CAPTCHA Image
Change Image
Write the characters in the image above


* = required field

Related Scripts:

Javascript email validation - simple version

Javascript check valid phone number

Javascript check for valid URL syntax

Javascript improved email validation script

Tags

[ isnumber ] [ numeric ] [ parseint ] [View tag cloud]






Tag Cloud    Submit a script


Latest Scripts Added

Pass null parameter in to parameterized query (ASP.net)
10 August 2010
If you try to use a parameterizes query like this: SqlCommand comm = new SqlCommand(); comm.CommandText = "insert into Authors (firstname, surname) values ...

Javascript List all properties for an object (Javascript)
23 March 2010
This code will expose all properities for a javascript object in a new window. Very handy little tool found here: http://www.faqts.com/knowledge_base/view.phtml/aid/8276

c# isNumeric function (ASP.net)
22 March 2010
There is no built in function for isNumeric, however there is a tryParse function that returns true if a string can be converted to a number. A quick and simple method for isNumeric is below.

ASP Hit Counter in Text File (ASP)
11 February 2010
This script will open up a text file and increment the value by 1. Can be used as a page specific hit counter (although using a separate google analytics profile is a better method)

ASP Replace in HTML (ASP)
10 February 2010
This function is designed to replace text in HTML strings so that only the non HTML code is replaced. If the searched for phrase is found in the body of the HTML, then the function will firstly ...