Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
hi...
I am using RAD Text box..I want to check that if user is entering the value in text box it should only character allow spacing its OK. I want it through JavaScript and should display the message box for user that should" enter character only" all this functionality should happen on click of Submit Button...
thanks!!!!!
Posted 17-Aug-11 21:49pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

<script>
function onkeydown(){
     var ch = String.fromCharCode(event.keyCode);
     var filter = /[a-zA-Z]/   ;
     if(!filter.test(ch)){
          event.returnValue = false;
     }
}
</script>
This can restrict the user to input only characters, but you still have to consider that user can paste numbers, or drag in into textbox.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use event.keyCode to accept only char values.
write a function in javascript and call it on onkeypress event of Textbox
 
function checkNum()
{
 
if ((event.keyCode > 64 && event.keyCode < 91) || (event.keyCode > 96 && event.keyCode < 123) || event.keyCode == 8)
   return true;
else
   {
       alert("Please enter only char");
       return false;
   }
 
}
  Permalink  
Comments
vivek_cool at 18-Aug-11 3:28am
   
hey thanks
but i want to include space also.. how i can i do this.
i.e. space can allowed
Member 9286545 at 26-Jul-12 6:52am
   
need to pass some value to above function .,,,,,how it could be??
Member 9286545 at 26-Jul-12 6:53am
   
and what is event above?

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

  Print Answers RSS
0 Maciej Los 295
1 OriginalGriff 259
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 187
4 Sinisa Hajnal 176
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 22 Apr 2014
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