Search This Blog

Loading...

Nov 20, 2010

How to Validate a Number in JavaScript


Sponsored Links:
<script type ="text/javascript" language="javascript">
function validateRealNumber(ctl)
{
var MytmpCtl;
var digits =".0123456789,";
var temp;
MytmpCtl = ctl
for (var i=0;i<MytmpCtl.value.length;i++)
{
temp=MytmpCtl.value.substring(i,i+1);
if (digits.indexOf(temp)==-1)
{
var erMsg=MytmpCtl.getAttribute('errormsg');
alert(erMsg);
MytmpCtl.focus();
return false;
}
}
return true;
}

 


How to Call

<body>
<
form id="form1" runat="server">
<
div>
<asp:Label ID="Label1" runat="server"
Text="Enter Salary:"></asp:Label>
<
asp:TextBox ID="TextBox1" runat="server"
onblur="javascript:validateRealNumber(form1.TextBox1)"
errormsg="Please enter a valid salary">
</
asp:TextBox>
</
div>
</
form>
</
body>

 


OutPut


image

Follow by Email