0

I want to make sure my regex match any number from 0-9, any word from a-z, and any of the following characteristics @#$&*:";?! irrespective of when its position in a word or sentence. If I have ab$2ww3&# my regex will give a positive result but if I have @#he&+#shsj it won't work because there is no number or jbsb2727hd3d won't work because the specific characters I need is not present. Please I need help on this

Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

0

Put all the characters you want to match inside a single character class.

[0-9a-z@#$&*:";?!]

let input = "asyeb336sheh33";
if (/[0-9a-z@#$&*:";?!]/.test(input)) {
  console.log('matched');
}

input = "dhd27shs3hj7";
if (/[0-9a-z@#$&*:";?!]/.test(input)) {
  console.log('matched');
}

input = "@#he&+#shsj";
if (/[0-9a-z@#$&*:";?!]/.test(input)) {
  console.log('matched');
}
Barmar
  • 741,623
  • 53
  • 500
  • 612