Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
Hi All
 
i need a javascript code for not allowing special characters and numbers and allow
spaces in my text box
 
thanks in advance
afsal
Posted 27-Jun-12 20:37pm
Comments
Sergey Alexandrovich Kryukov at 28-Jun-12 1:56am
   
What are those "special characters"? There is no such thing.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This article contains a small JS framework which contains what you need. also many more of similar nature.
 
A Tiny Javascript Framework for Common Validation Scenarios.[^]
 
P.S. just use the AcceptAlphabetOnly function with argument for spaces as true.
  Permalink  
v2
Comments
afsal.mp at 28-Jun-12 1:50am
   
thanks rahul .. this solution solved my problem
Rahul Rajat Singh at 28-Jun-12 1:55am
   
you are welcome. if it worked then please mark the answer as solution as this would let other know that the problems is solved and the others with similar problem can also refer and benefit from it.
afsal.mp at 28-Jun-12 2:07am
   
done it
Rahul Rajat Singh at 28-Jun-12 2:09am
   
thanks.
afsal.mp at 28-Jun-12 2:44am
   
hi .. if u dontmind let me know how to allow dot(.) in this javascript
afsal.mp at 28-Jun-12 2:45am
   
i got it thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is a simple sample of similar thing:
Here is how to filter out:
<html>
   <head>
      <script type="text/javascript"><!--
         function filterDigits(eventInstance) { 
            eventInstance = eventInstance || window.event;
                key = eventInstance.keyCode || eventInstance.which;
            if ((47 < key) && (key < 58) || key = 45 || key == 8) {
               return true;
            } else {
                    if (eventInstance.preventDefault) eventInstance.preventDefault();
                    eventInstance.returnValue = false;
                    return false;
            } //if
         } //filterDigits
      --></script>
   </head>
<body">
 
<input type="text" onkeypress="filterDigits(event)"/>
 
</body>
</html>
 
Pay attention that the key code 8 (backspace) is allowed. By some historical reason, this key is considered as a character, so it should be specifically allowed through the filter.
 
—SA
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 325
1 DamithSL 300
2 Sergey Alexandrovich Kryukov 289
3 CPallini 235
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 28 Jun 2012
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