Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
1.10/5 (3 votes)
Dear All,

I have a Textbox, user must enter only alphabets into that textbox.

Please I need JavaScript for this.



Thank you sir.
Posted
Updated 14-Jul-17 0:07am

Google is a marvellous tool. But only if you actually bother to use it...

Google[^]
Top hit: How to Restrict user to enter only alphabates in TextBox by javascript in asp.net[^]

In future, please try to do at least basic research yourself, and not waste your time or ours.
 
Share this answer
 
There are ways to make this happen, using regular expression, JavaScript validation, etc.

I would prefer Masked Textbox for it, something like: Enhanced Textbox Control[^]
 
Share this answer
 
JavaScript
var value = "a";
var reg = new RegExp("[A-Za-z]");

if (!reg.test(value)) {
   return false;
}


try with this.

Thanks,
Mamun
 
Share this answer
 
v2
you must add from Toolbox in Validation and select RequiredExpressionValidator;
and in properties "ControlToValidat" select filed name ex: Textbox1
and select Expression mask from ValidationExpression

for alphabets "\w+"


S.Dwaik
 
Share this answer
 
C#
function onlyAlphabets(e, t) {
try {
if (window.event) {
var charCode = window.event.keyCode;
}
else if (e) {
var charCode = e.which;
}
else { return true; }
if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
return true;
else
return false;
}
catch (err) {
alert(err.Description);
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900