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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

does anyone know how to check for \ in a text box substr does not work 1

Status
Not open for further replies.
Apr 22, 2008
9
US
I'm trying to have a text box that the user will copy/paste a file destination into. I'm validating that the user pasted correctly and that the beginning of the string starts with \\ any ideas?
 
you can use the match method.
Code:
var myval = document.getElementById('myid').value;
if(myval.match("\") == "\"){
   do whatever;
}

if you want to check if something is NOT in the string you can use...
Code:
var myval = document.getElementById('myid').value;
if(myval.match("\") == null){
   do whatever;
}

hope it helps.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
sorry you need to use two slashes ("\\") , i only showed one as that's what your thread heading showed - lol

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
thinking about it you might have to escape them!

so
Code:
if(myval.substring(0,2) == "\\\\"){do whatever;}

could do it.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top