http://www.webmasterworld.com/javascript/3519735.हतं
adresindeki
/** * A helpful link: http://www.quirksmode.org/js/keys.html * The event will have two different properties: * keyCode: the actual keyboard key the user pressed * charCode: the ASCII value of the resulting character * * onkeypress events register in different properties for each of the * browsers, some in the charCode, others in the keyCode. And some * will not register keyboard movement keys whatsoever so the * onkeypress event will not even be fired at all. With onkeydown/up * the keyCode always holds the key code. * // +-----------------------------------------------------------------------+ * For instance, a lower case 'a' and an upper case 'A' have the same * keyCode because the user presses the same key, but a different charCode * because the resulting character is different. Explorer and Opera do not * support charCode. However, they give the character information in the * keyCode, but only onkeypress. Onkeydown/up keyCode contains the key info. * * Some general definitions of onkeypress events: * ------------------------------------------------ * character: numeric value of keyboard character key (alphanumeric, etc.) * movement: numeric value of keyboard "movement" key (up, delete, etc.) * * The following table shows which event property will be populated for two * of the major browsers. Windows onkeypress will not register movement * keys so the event would be undefined. * * Event event.charCode event.keyCode * --------- -------------- ------------- * character Mozilla Windows * movement Mozilla * * character keys: * ------------------- * 44 Comma * 46 Period * 48-57 Digits 0-9 * movement keys: * ------------------- * 8 Backspace * 9 Tab * 32 Space * 33 Page Up * 34 Page Down * 35 End * 36 Home * 37 Arrow Left * 38 Arrow Up * 39 Arrow Right * 40 Arrow Down * 46 Delete * 48-57 Digits 0-9 */ function checkMoneyOnlyMillions(elm, desc, msg) { desc = (desc)? desc : elm.name msg = (msg)? false : true var reMoneyOnly = /^\d{0,9}(\.\d{0,2})?$/ if (elm.value &&!reMoneyOnly.test(elm.value)) { if (msg) { alert('The ' + desc + ' accepts monetary values only, up to the millions with two decimal places (123456789.12).') elm.focus() elm.select() } return false } return true } function checkNumbersOnly(elm, desc, msg) { desc = (desc)? desc : elm.name msg = (msg)? false : true var reNumbersOnly = /[^\d]/ if (elm.value &&!reNumbersOnly.test(elm.value)) { if (msg) { alert('This field accepts decimal numbers only.') elm.focus() } return false } return true } function numOnly(evt) { evt = (evt)? evt : ((window.event)? window.event : "") if (evt) { var charCode = (evt.charCode)? evt.charCode : evt.keyCode // Backspace (8), tab (9), space (32), page up/down (33-34), end (35), home (36), arrow keys (37-40), delete (Mozilla.event.keyCode=46), digits 0-9 (48-57) // MSIE movement keys do not register a keyCode event (the evt.which property will be 'undefined'; Mozilla registers 0) if ((charCode!= 8 && charCode!= 9) && charCode <> 40 && charCode <> 57) { window.status = "This field accepts numbers only." return false } } window.status = "" return true } function moneyOnly(evt) { evt = (evt)? evt : ((window.event)? window.event : "") if (evt) { // evt.which and evt.charCode are undefined in Windows, evt.keyCode is the keyboard character value in Windows (keyboard movement keys do not trigger an onkeypress event!) // evt.which is the keyboard character value in Mozilla, evt.keyCode is the keyboard movement keys in Mozilla var charCode = (evt.charCode)? evt.charCode : evt.keyCode if (charCode!= 46 &&!numOnly(evt)) { window.status = "This field accepts monetary values only." return false } window.status = "" return true } }