Wednesday, August 11, 2004

Numeric TextBox - A Simple Way!


Numeric TextBox - A Simple Way!










One of my site visitor ask me a query that he
wants Numeric TextBox in Asp.NET, i suggested him to use javascript but he was
haveing problem on how to write it in javascirpt. i send him this
code

function IsNumeric(e)
{

if (isNaN(e.value) == true)

{
alert("VALUE SHOULD BE
NUMERIC");
e.value =
"";

e.focus();
return
false;
}

else
return true;
}
<INPUT
type="text" name="amount" onkeyup="return IsNumeric(this)">


but then i thought can't we do that in a
simple one line. the thought lead me to Investigate
and i found one can use RegEX to do the same in ONE Line...


<INPUT type="text" name="decimal"
onkeyup=
'this.value=this.value.replace(/[^\d]*/gi,"");' />



Regards,
Mitesh v. Mehta

No comments: