Avatar of Chadd C
Chadd C
 asked on

JS Special Character Valitation

I am attempting to include  [  ]  $  ?  \  in the below snippet. I tried to escape them to no avail. What is the proper syntax for this string?

   
function validate_desc(val){
        if ( val.match("^[a-zA-Z0-9,-. \\\\/(/)#/_/'\":]+\$") ) {
            return true;
        } else {
            return false;
        }
    }

Open in new window

JavaScript

Avatar of undefined
Last Comment
Zvonko

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Julian Hansen

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.
Zvonko

Check this:
function validate_desc(val){
      var inv = val.match(/[^\w\,\-\.\ \\\/\(\)\#\'\"\:]/g);
        if ( inv ) {
         console.log("Invalid chars: "+inv.join(' '));
            return false;
        } else {
            return true;
        }
    }

Open in new window


It return  false  if  any character is found tht is NOT in this list:  \w , - . blank \ / ( ) # ' " :


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