Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

validation code / function to allow only NUmbers in a text box

Answer Posted / kevin konkle

//Have this be called off the keypress event of your
textbox control.
function numberFormat(fld, e)
{
var key = '';

//This string contains all characters you want to allow
var strCheck = '0123456789';
var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) return true; // Enter
if (whichCode == 8) return true; // Delete

// Get key value from key code
key = String.fromCharCode(whichCode);

// Not a valid key
if (strCheck.indexOf(key) == -1) return false;

//If it is a legal value then add it to the text box
fld.value += key;

return false;
}

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to create an anonymous function

2080


how to Auto Scroll the page

1993


sample code to auto focusing the first field in a form

2412


How to encode and decode URL strings?

2241


how to create a Draggable element

2358


How to block double clicks

2060


code to detect versions of different browsers like internet explorer, netscape, mozilla, opera etc

2107


code to positioning of window in certain dimensions

2071


Create a Menu that can be activated while clicking on Right Mouse button

2074


program to show a progress bar

2559


Code to Block submission of form by pressing Enter Key

2456


maximizing the main window

2015


how to create Expandable and Collapsible Menus

3183


write a code to generate pseudorandom numbes

2304


determine which Element received an Event

2287