0

I have a regex text I'm working on. It already works pretty well but it returns false for strings that contain already defined characters when i really want it to return true. Here is my current code:

const regexTest=()=>{

let regex = /^[ A-Za-z0-9\\?.,><|./#&+-]*$/g

return regex.test(str)
}

console.log(regexTest("111"));     //returns true
console.log(regexTest("a"));       // returns true
console.log(regexTest("a @ a"));   //returns false
console.log(regexTest(`sfbhjv!`));  //returns false

What i want is for the regex to return true as long as the string contains a defined character class. How do I go about this?

Chidex
  • 139
  • 2
  • 10

0 Answers0