»
EnglishFrenchVietnamese

Print - Validation (Number) - JavaScriptBank.com

Full version: jsB@nk » Form » Validation » Validation (Number)
URL: https://www.javascriptbank.com/validation-number.html

Validation (Number) © JavaScriptBank.comValidates an input field to make sure that only number is entered. If you enter letter it alert.

Full version: jsB@nk » Form » Validation » Validation (Number)
URL: https://www.javascriptbank.com/validation-number.html



JavaScript
<script>/*You can use this script to check the numeric value of multiple fields with the sequnce numberi.e        for example there are two field to enter telephone number of a particular person;                  checkNumber(1, "frmData", "Telephone")                  checkNumber(2, "frmData", "Telephone")If you want to check for just one field just pass null value to nCount fieldie checkNumber(null, "frmData", "Salary")*/function checkNumber(nCount, frmName, txtId){var nText = eval("Number(document." + frmName + "." + txtId + "" + nCount + ".value)");if (nText.toString() =='NaN'){alert('Invalid value,\nplease enter numeric value');eval("document." + frmName + "." + txtId + "" + nCount + ".value='';")eval("document." + frmName + "." + txtId + "" + nCount + ".focus();")}}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form id="frmDetail" name="frmDetail"><input type="text" id="Telephone1" name="Telephone1" onblur="Javascript: checkNumber(1, 'frmDetail', 'Telephone');" size="20"><input type="text" id="Telephone2" name="Telephone2" onblur="Javascript: checkNumber(2, 'frmDetail', 'Telephone');" size="20"></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->