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
how to create an anonymous function
how to Auto Scroll the page
sample code to auto focusing the first field in a form
How to encode and decode URL strings?
how to create a Draggable element
How to block double clicks
code to detect versions of different browsers like internet explorer, netscape, mozilla, opera etc
code to positioning of window in certain dimensions
Create a Menu that can be activated while clicking on Right Mouse button
program to show a progress bar
Code to Block submission of form by pressing Enter Key
maximizing the main window
how to create Expandable and Collapsible Menus
write a code to generate pseudorandom numbes
determine which Element received an Event