Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 22-Aug-11 21:31pm
Comments
OriginalGriff at 23-Aug-11 3:36am
   
Reason for my vote of one: too lazy to do basic research.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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...
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

It is time to learn both Javascript and regular expressions (and, in the spare time, have a look at the Q&A FAQ).
  Permalink  
Comments
Member 9435088 at 30-Oct-12 2:22am
   
DHARMENDRA HOW TO ALPHA BETHA VALIDATION URGENT
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try this:
 
<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:
 
<input type="text" name="name" id="name"  onblur="checkField(this)">
  Permalink  
v4

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

  Print Answers RSS
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 325
2 OriginalGriff 313
3 ClimerChinna 222
4 Zoltán Zörgő 170
0 Sergey Alexandrovich Kryukov 8,243
1 OriginalGriff 7,109
2 CPallini 2,598
3 Richard MacCutchan 1,980
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 23 Aug 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100