How to enable alphanumeric characters in a text box?

How to enable alphanumeric characters in a text box?




function EnableAlphanumeric()
{
if((keyCode>=65 && keyCode<=90) || (keyCode>=97 && keyCode<=122) || (keyCode>=48 && keyCode<=57) || (keyCode==32)) {
event.returnValue = true; }
else
{
event.returnValue = false;
}
}


Call this function in the textbox


Comments

Author: shital07 Jun 2010 Member Level: Bronze   Points : 1


private void textbox1_KeyPress(object sender, KeyPressEventArgse)
{
if (!char.IsDigit(e.KeyChar) && !char.IsControl (e.KeyChar)&&!char.IsLetter (e.KeyChar))

e.Handled = true;
}

Author: Mohanakrishnan07 Jun 2010 Member Level: Gold   Points : 1

function num(e)
//this function is only allow the character [a-z]/[A-Z]/[0-9]
{
var k;
document.all ? k =e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || (k > 47 && k < 58));
}

//call the above function in javascript textbox keypress event
(asp:TextBox ID="txt" runat="server"
onkeypress="return isNumber();">

Author: Phagu Mahato12 Feb 2014 Member Level: Gold   Points : 5

Code snippet for enable alphanumeric characters in a text box


private void textBox_KeyPress(object sender, KeyPressEventArgs e)

{

if (Char.IsLetterOrDigit(e.KeyChar)

||e.KeyChar == '\b')

{

e.Handled = false;

}

else

{

e.Handled = true;

}

}

Or another code snippet
Function Isnumber(ByVal KCode As String) As Boolean
Isnumber = True
If Not IsNumeric(KCode) And KCode <> ChrW(Keys.Back) And KCode <> ChrW(Keys.Enter) And KCode <> "."c And KCode <> ","c Then
Isnumber = False
MsgBox("Please Enter Numbers only", MsgBoxStyle.OkOnly)
End If

End Function



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: