Click here to Skip to main content
13,736,558 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 8 Apr 2008
Licenced CPOL

Number Validation and Formatting using Javascript

, 8 Apr 2008
Rate this:
Please Sign up or sign in to vote.
Numberic value validation and formatting using Javascript


The control uses javascript to handle number formatting as you keep typing and does the validation as well. For one of our requirement, we needed a javascript based control that did formatting as the users kept typing. Google search only yielded script that did formatting on focus change events only. So I went about creating a new control myself.


The idea for this control came from one of our client requirement that needed a small javascript to have a textbox that will take big numbers. The numbers can have unlimited decimal places. Also the script will do 3 things at the same time.
1- It should only allow numbers (negative as well) and "." To be entered.
2- It should format the number as 1,234,567,789.123456789. It should execute such that the the commas are put while typing.
3- It should also only allow numbers that are as big as double can handle.

Using the code

Using the control is very easy and just needs adding the javascript code from the source page.

On the textbox on which the formatting needs to be applied, use the following code

onkeypress="return ValidateNumberKeyPress(this, event);" onkeyup="ValidateNumberKeyUp(this);"

Points of Interest

Script is preety easy to read and understand. Some references that were used during the course of the script creation


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Team Leader
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralGreat work Pin
ismail Hingoro7-Sep-09 23:09
memberismail Hingoro7-Sep-09 23:09 
GeneralGreat script Pin
23-Jan-09 3:43
member23-Jan-09 3:43 
GeneralThank you Pin
MrRolly12-Jun-08 18:32
memberMrRolly12-Jun-08 18:32 
Generaland one wish.. Pin
berkcan17-May-08 6:48
memberberkcan17-May-08 6:48 
GeneralRe: and one wish.. Pin
shokisingh12-Jun-08 7:58
membershokisingh12-Jun-08 7:58 
GeneralHey thanks ! Pin
berkcan17-May-08 6:22
memberberkcan17-May-08 6:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06-2016 | 2.8.180920.1 | Last Updated 8 Apr 2008
Article Copyright 2008 by shokisingh
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid