Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with using indexOf("\")

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm trying to validate a text field (and form) and check to see whether it contains 'illegal' characters.

The lines:

if (ctitle.indexOf("!") != -1){errormsg += "\n -> The title cannot contain a '!'"}
if (ctitle.indexOf("@") != -1){errormsg += "\n -> The title cannot contain a '@'"}
if (ctitle.indexOf("/") != -1){errormsg += "\n -> The title cannot contain a '/'"}

works fine, but when I try to use:

if (ctitle.indexOf("\") != -1){errormsg += "\n -> The title cannot contain a '\'"}

I get an "illegal character" from the browser. Obviously its to do with "\" but I'm not sure how to fix it. Can someone please tell me how to get around this! Thanks, any help is much appreciated.

 
maybe

ctitle.indexOf("\\")

or

var slash = String.fromCharCode(92);
ctitle.indexOf(slash)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top