Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a textbox and it need the user not allow to enter any specialcharecters He can enter

1. A-Z
2. a-z
3. 0-9
4. Space.
Posted
Comments
OriginalGriff 23-Aug-11 3:36am    
Reason for my vote of one: too lazy to do basic research.

Google! A very simple search using "validate alphanumeric in javascript" copied from your question subject gave 1.3 million hits, most of then explaining exactly how to do it.

Please, try to do at least basic research your self in future...
 
Share this answer
 
It is time to learn both Javascript and regular expressions (and, in the spare time, have a look at the Q&A FAQ).
 
Share this answer
 
Comments
Member 9435088 30-Oct-12 2:22am    
DHARMENDRA HOW TO ALPHA BETHA VALIDATION URGENT
try this:

XML
<script type = "text/javascript">
function checkField(fieldname)
{
if (/[^0-9a-bA-B\s]/gi.test(fieldname.value))
{
alert ("Only alphanumeric characters and spaces are valid in this field");
fieldname.value = "";
fieldname.focus();
return false;
}
}
</script>


and call it like this:

HTML
<input type="text" name="name" id="name"  onblur="checkField(this)">
 
Share this answer
 
v4

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