Tuesday, November 13, 2007

Usefull validation javascripts - Sanjeewa Sapumana

function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode <> 57))
return false;
return true;
}
function ValidateHour(text)
{
//alert(text.value);
if(text.value!='')
{
if(parseInt(text.value) <>24)
{
alert('Invalid Hour value');
text.value='';
text.focus();
return false;
}
}
//return true
}
function ValidateMinutes(text)
{
if(text.value!='')
{
if(text.value < "0" && text.value>60)
{
alert('Invalid minute value');
text.focus();
}
}
}


function isDecimalKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && (charCode <> 57) && charCode!=46)
return false;
return true;
}
function CheckDecimalKey(num)
{
if (isNaN(num.value))
{
alert('Invalid value');
num.value='';
}
}

No comments: