Hi, I am using this code to enter only numbers in a textbox and works perfectly. <script type="text/javascript"> function fnAllowNumeric() { if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 8) { event.keyCode = 0; alert("Please Enter Number Only"); return false; } } </script> Now on top of this I should allow minus sign to be entered at the start. Can anyone suggest me some solutions?
<script> function myFunction() { var a = document.getElementById("txt").value.trim(); if (isNaN(a) || a == ""){ alert("Not a valid number!"); } else { alert("A valid number!"); } } </script> <input type="text" value="" id="txt"> <button onclick="myFunction()">Click me</button>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)