»
EnglishFrenchVietnamese

Print - Validate Numeric Only - JavaScriptBank.com

Full version: jsB@nk » Form » Validation » Validate Numeric Only
URL: https://www.javascriptbank.com/validate-numeric-only.html

Validate Numeric Only © JavaScriptBank.comThis JavaScript verifies that a string is numeric, otherwise it deletes the non-numeric character.

Full version: jsB@nk » Form » Validation » Validate Numeric Only
URL: https://www.javascriptbank.com/validate-numeric-only.html



JavaScript
<script language="javascript">// Created by: Manzi Olivier :: http://www.imanzi.com/// calculate the ASCII code of the given characterfunction CalcKeyCode(aChar) {  var character = aChar.substring(0,1);  var code = aChar.charCodeAt(0);  return code;}function checkNumber(val) {  var strPass = val.value;  var strLength = strPass.length;  var lchar = val.value.charAt((strLength) - 1);  var cCode = CalcKeyCode(lchar);  /* Check if the keyed in character is a number     do you want alphabetic UPPERCASE only ?     or lower case only just check their respective     codes and replace the 48 and 57 */  if (cCode < 48 || cCode > 57 ) {    var myNumber = val.value.substring(0, (strLength) - 1);    val.value = myNumber;  }  return false;}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name="myForm" method="post" action="#">  Enter an integer here: <input name="txtNumber" type="text"    id="txtNumber" onKeyUp="javascript:checkNumber(myForm.txtNumber);"></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->