|
|
Accept only integers with dot(.) operator - Javascript
|
Views : 447
|
|
Tagged in : Javascript
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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)">
|
|
By Nirmala, On - 2010-09-22 |
|
|
|