Hi,
I am using a form in my project and in that form there is a text box which should take only numbers and also only one decimal point numbers or just normal integers for ex: 10, 10.55, 11.66 or so on... it should not take more than a single decimal point for ex: 10.5.4 should not take.
I had done it using javascript as follows:
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
this allows only numbers and also point that is "." so it takes any number of points to restrict i used like this js:
function checkDec(el) {
var ex = /^[0-9]+\.?[0-9]*$/;
if (ex.test(el.value) == false) {
alert('Incorrect Number');
}
the text box i used was like this :
<input type="text" class="TextBox" runat="server" id="txtDateFrom" onkeypress="return isNumberKey(event);" onblur="checkDec(this);" />
But this is not restricting the decimal point to single decimal point. PLease help me with how i can i restrict user and allow them to enter a single decimal point .... and should i use any onclick event ? what i prefer ia an onkeypress event check ... Is that Possible please help...
Thanking You in advance!!