Avatar of tonelm54
tonelm54
 asked on

Regex for special characters

Im trying to find out if a textbox for a password contains a special character, so written the following code:-
$("#txtPassword").on("keyup", function () {
	if ($("#txtPassword").val().match(/(.*[!,%,&,@,#,$,^,*,?,{,},|,(,),[,],_,-,/,\])/)) {
  	$("#tdContainsSymbol").html("P");
  } else {
  	$("#tdContainsSymbol").html("O");
  }
});

Open in new window


However its saying there is an issue with the regex command, Im assuming its to do with escape characters so changed the characters like []|\ and put a \ as an escape character, but didnt work.

Any ideas?
Regular ExpressionsJavaScript

Avatar of undefined
Last Comment
tonelm54

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Terry Woods

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Terry Woods

I tested the pattern here: https://jsfiddle.net/7as3wu8o/
tonelm54

ASKER
Excellent, worked great :-)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck