Saturday, July 28, 2007

JavaScript to Allow Alfabets and Numbers in a TextBox

Write this in the HTML Part

Please Inculde the JavaScript Tag and place the below function in it.

function fnAllowAlphaNumeric()
{
if ((event.keyCode != 9 && event.keyCode != 95)&&(event.keyCode < 48 || event.keyCode > 57 ) && (event.keyCode != 46) && (event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 97 || event.keyCode > 122)) event.returnValue = false;
}
Close the Script Tag.

Write this in the CodeBehind Part

and in the Page_Load write like this
Page_Load
{
this.txtAlfaNumeric.Attributes["OnKeyPress"] = "JavaScript:return fnAllowAlphaNumeric()";
}

0 comments: