Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

special character check in text box

 
BhanuMurthy Venkata
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I want to check whether the user has entered any special characters in a text box.

If the user enters, i want to display an alert message stating that he cant enter a special character (like �).

bhanu
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.
Try it out and let us know how it turns out.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a job for a regular expression. You can write a regular expression to match the characters you want, then see whether your input matches it.
By the way: If you are French or Spanish, then � is not a special character.
 
BhanuMurthy Venkata
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i wrote some thing like this but it is not working can you please correct me where am doing wrong

<script language="JavaScript">
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
for (var i = 0; i < document.formname.Text1.value.length; i++) {
if (iChars.indexOf(document.formname.Text1.value.charAt(i)) != -1) {
alert ("The box has special characters. \nThese are not allowed.\n");
return false;
}
}
</script>
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by BhanuMurthy Venkata:
i wrote some thing like this but it is not working can you please correct me where am doing wrong

Well to start, you have posted in the wrong forum. We have a special forum for HTML and JavaScript. See also Carefully Choose One Forum.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question wasn't about JavaScript when I last saw it . . . moving (quickly!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic