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

regular expression

Status
Not open for further replies.

4345487

Programmer
Dec 31, 2002
132
US

Hi,

Does anyone has a sample of how to validate a value using regular expressions.

I want to know if a field value contains any of this 9 characters.


" # + ' / ; < > \

Thanks
 
Code:
var myRE = new RegExp("[\"#+'/;<>\\]+","g");
if ( myRE.test([i]testString[/i]) ) then
   alert("Found special character");

Meddle not in the affairs of dragons,
for you are crunchy, and good with mustard.
 

Hi,

Thanks for the quick response looks like everythingworks OK
except the \ I try to fixed but no luck. I get the error

error: expected "]"m in regular expresion.
 
Using a backslash in any regular expression is problematic - since it has such a strong meaning. Usually using two \\ in a row is the proper way to signify a literal \, but not with every language. Did you try using just a single \ there at the end? May be if the character after it has no special meaning when escaped by \ it will interpret the \ as literal.

Unfortunately the regular expression page in MSDN is no help. It doesn't even mention using \ to escape characters which have meaning into regular characters.

It also may be that escaping the quote with \ is unnecessary with a character class (i.e. the [ ] ), so it is already picking up the \ from there. Guess I can try to do some experimenting...

Meddle not in the affairs of dragons,
for you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top