Allow Numeric OR Numbers with dot only using java script

Allow Numeric OR Numbers with dot only using java script

I am going to explain here allow only numbers to be typed in a textbox i.e. numeric value or digits in TextBox using JavaScript. Also disabled the input via Dropping and Pasting the value. so that user not allow to directly drop or paste non numeric value in textbox

HTML

Numeric Value : <input type="text" id="amount" name="amount" onkeypress="return isNumberKey_With_Dot(event);" ondrop="return false;" onpaste="return false;" />
<span id="errormsg" style="color: Red; display: none">* Input digits (0 - 9)</span>

JAVASCRIPT

<script type="text/javascript">
var specialKeys = new Array();
specialKeys.push(8); //Backspace 
function isNumberKey_With_Dot(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode > 31 && (charCode < 48 || charCode > 57)) || specialKeys.indexOf(keyCode) != -1){
if(charCode == 46)
    return true;
else
    return false;
}
else
    return true;
}
</script>

0 Comments

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed

>