Accept only integers with dot(.) operator

by Nirmala 2010-09-22 17:10:51

Accept only integers with dot(.) operator
Use the below code to accept only integers with dot(.) operator for textfield.

function integerwithdot(s,iid)
{
var i;
s = s.toString();
for (i = 0; i < s.length; i++)
{
var c;
if(s.charAt(i)==".")
{
}
else
{
c = s.charAt(i);
}
if (isNaN(c))
{
alert("Given value is not a number");
document.getElementById(iid).value="";
return false;
}
}
return true;
}
<input type="text" id="txt" onkeyup="integerwithdot(this.value,this.id)">

Tagged in:

1253
like
0
dislike
0
mail
flag

You must LOGIN to add comments