aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes special character check in text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "special character check in text box" Watch "special character check in text box" New topic
Author

special character check in text box

BhanuMurthy Venkata
Greenhorn

Joined: Nov 30, 2008
Posts: 8
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

Joined: Jul 26, 2007
Posts: 10376
    
    8

Ok.
Try it out and let us know how it turns out.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
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

Joined: Nov 30, 2008
Posts: 8
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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
The question wasn't about JavaScript when I last saw it . . . moving (quickly!)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: special character check in text box