Friday, October 5, 2007

Some Valueble Javascript Validation Code

//Check if Numbers entering//
------------------------------

function isNumberKey(evt)
{ var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && (charCode <> 57) )
return false;

return true;
}

//Check if pressing decimal keys//
-----------------------------------

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='';
}
}

//Delete confirmation//
-----------------------

function deleteConfirm() {
if(confirm('Are you sure, you want to delete this record?'))
{
return true;
}
else
{
return false;
}
}

//Max length restriction //
---------------------------
function MaxLengthRestrict(text,long) {
var maxlength = new Number(long);
// max length.
if (text.value.length > maxlength)
{
//return false;
text.value = text.value.substring(0,maxlength);
alert("Allowed only " + long + " characters");
}
}

//

---------------------------------------------------
how to call the event on c# code
======================

onkeypress="return isNumberKey(event);">

No comments: