Thursday, October 8, 2009

Javascript valdation for textbox langth valdation

< script type="text/javascript" language="javascript" >
function checkCharacterLimit(TB)
{
var maxCharacters = 200;
var withinCharacterLimit = true;
var ValidateTB = document.getElementById(TB.id);
var charCode = ( event.which ) ? event.which : event.keyCode;
var bool=(charCode =="8" || charCode =="46");
if (ValidateTB.value.length > maxCharacters && !bool)
{
withinCharacterLimit = false;
}
return withinCharacterLimit;
}
< /script >

in c# code Add following code

txtJobDiscription1.Attributes.Add("onKeyDown", "return checkCharacterLimit(this);");

No comments: