Monday, June 9, 2008

number validatuion in textbox using Javascript

function typecheck(obj)
{
var check=false;
var val=obj.value;
var s=new Array("0","1","2","3","4","5","6","7","8","9");
var len=val.length;
for(i=0;i<len;i++)
{
for(j=0;j<s.length;j++)
{
if(obj.value.charAt(i)==s[j])
{
check=false
break;
}
else
{
check=true
}
}
}
if(check==true)
{
obj.value="";
obj.focus();
alert("Please type valid number");
return false;
}
}

Note:Call using onkey up event in html..

<asp:TextBox ID="txtbox" runat="server" onkeyup="javascript:return typecheck(this)" ></asp:TextBox>