Image
codetoad.com
��ASP Shopping Cart,�Forum�&�BBS
��- all for $20 from CodeToad Plus!
ImageImage
Image
Image
��Home�||�ASP�|�ASP.Net�|�C++/C#�|�DHTML�|�HTML�|�Java�|�Javascript�|�Perl�|�VB�|�XML�||�CodeToad�Plus!�||�Forums�||�RAM
Search Site:
Image Image


Home���Javascript���Article

Javascript IsNumeric Function

Article by: ImageJeff Anderson( 1362 ) (2/26/2002)
Bookmark us now! Add to Favourites
Email a friend! Tell a friend
Summary: A javascript validation function to check whether the details entered by a user are numeric.
Viewed: 1072861 times Rating (199 votes):�
ImageImage Image Image Image Image
�0 out of 5
Image Rate this Article Image Read Comments Image Post Comments


The simplest way to check whether the details entered in a text field are numeric is to to loop through the string and compare each character to a pre-defined list of acceptable characters.

In this function, we've allowed decimal points and numbers nought through 9.

We use two methods to help us here : the charAt and indexOf.

Using the charAt method, we can find out which character is filling a designated position within a string. We then use the indexOf method to search our ValidChars list of valid characters. If it doesn't exist, (if ValidChars.indexOf(Char) == -1) this means the user has entered an invalid character. Here's the full function.



function IsNumeric(sText)
{ ���var ValidChars = "0123456789."; ���var IsNumber=true; ���var Char; ���for (i = 0; i

To understand how to use the IsNumeric function to validate a form, see Form Validation function Page.






Useful Links
Image

CodeToad Experts
Image
Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Image Rate this article: ����Poor Excellent
View highlighted Comments
ImageUser Comments on 'Javascript Isnumeric function'
RELATED ARTICLES
Javascript - Enable and Disable form elements
by Jeff Anderson
This is a relatively little known and under-used feature of javascript which can be very useful in guiding a user through a form. Using the disabled tag, you can switch on and off elements in a form.
Image
Check IsNumeric Function
by Jeff Anderson
A javascript validation function to check whether the details entered by a user are numeric.
Image
Javascript Onload Event
by Jeff Anderson
Sometimes you need to perform an action immediatley after the page has loaded. That's when the onLoad Event Handler comes in handy
Image
Form Validation Function
by Jeff Anderson
A javascript validation function that you can use to validate all types of forms.
Image
Javascript Get Selected Text
by Jeff Anderson
A cross-browser script to get text selected by the user
Image
JavaScript Field Is Empty Form Validation
by Jeff Anderson
This javascript function allows you to check whether a form field has been completed or not.
Image
Check Email Validation Function
by Jeff Anderson
A javascript validation function to check whether the user has entered a valid email address in a form.
Image
Javascript onUnload Event Handler
by Jeff Anderson
The onUnload Event Handler allows you to perform an action as the user leaves the page.
Image
Multiple submit buttons on a single form
by Kiran Pai
This script shows you how to submit the contents of a form to different programs depending on which Submit button you press. Additionally it also shows how to call two different functions when you press the Submit button.
Image
Simple date validation
by Chris Hogben
function that takes a date in three parts, day, month and year - returns true if it's a valid date.
Image








Recent Forum Threads
•� Run a program both on windows and linux
•� VERO.SurfCAM.v2014
•� Schlumberger.Petrel.V2013.2
•� Petrel.V2013.2
•� Altair.HyperWorks.v12
•� VoluMill.v6.1
•� VoluMill.NEXION.6
•� VERO.SurfCAM.v2014
•� Schlumberger.Petrel.V2013.2


Recent Articles
Image ASP GetTempName
Image Decode and Encode UTF-8
Image ASP GetFile
Image ASP FolderExists
Image ASP FileExists
Image ASP OpenTextFile
Image ASP FilesystemObject
Image ASP CreateFolder
Image ASP CreateTextFile
Image Javascript Get Selected Text


Image Image
� Copyright codetoad.com 2001-2015