Internet is growing Every Seconds :: Industry is growing Every Year

Wednesday, February 16, 2005

Javascript: Key press Client side validation

Description:

This function is used to control the user can
only entered the number in textbox. On key press Event is occurred when
the
user enter the data in this text box (m_phno). If the user press the
integer
value 1 in this textbox the num_only()function is called .
event.keyCode return
the values is 48.So this function return the True and its accepts this
letter
otherwise return false and values is not entered in Text box.



Code


< script Language="JavaScript" >
function num_only()
{
//alert (event.keyCode);
if (event.keyCode > 47 && event.keyCode < 58 )
{
return true;
}
else
{
event.keyCode=0;
return false;
}
}

function alpha_char()
{
// alphabet with blankspace
//alert (event.keyCode);
if (event.keyCode>96 && event.keyCode <123)//smal
{
return true;
}

if (event.keyCode>64 && event.keyCode <91) //cabs
{
return true;
}


if (event.keyCode==32) //blankspace
{
return true;
}

event.keyCode=0;
return false;

}


< /script >


< form name=nb_frm >
< INPUT type=text name=m_phno id=m_phno value=""
onkeypress="num_only();" >

< / Form>