• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

special character check in text box

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.
Try it out and let us know how it turns out.
 
Marshal
Posts: 76415
365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 76415
365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question wasn't about JavaScript when I last saw it . . . moving (quickly!)
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic