Tuesday, November 4, 2008

Javascript to check if user input has digit in it.

function HasDigit(txt)
{
strLen = txt.length;

for(i=0 ; i < strLen ; i++ )
{
if( (txt.charAt(i)=="0") || (txt.charAt(i)=="1") || (txt.charAt(i)=="2") || (txt.charAt(i)=="3") ||
(txt.charAt(i)=="4") || (txt.charAt(i)=="5") || (txt.charAt(i)=="6") || (txt.charAt(i)=="7") ||
(txt.charAt(i)=="8") || (txt.charAt(i)=="9"))
{
return true;
}
}
return false;

}

No comments: