Validating Only Numbers using Javascript

Self-Innovator
Posted by Self-Innovator under JavaScript category on | Points: 40 | Views : 1192
Javascript function to Validate Age
function EnterOnlyNumbers(x)

{

var len=x.value.length;

var s_charcode=0;

for(var s_i=0;s_i<len;s_i++)

{

s_charcode=x.value.charCodeAt(s_i);

if(!((s_charcode>=48 && s_charcode<=57)))

{

alert("Enter only numbers");

x.value="";

x.focus();

return false;

}

}

return true;

}


Page Design

<asp:textbox id="txt1" ruat="server" onChange="EnterOnlyNumbers(this)">

Comments or Responses

Login to post response