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
            Asked
            
        
        
            Active
            
        
            Viewed 20 times
        
    0
            
            
         
    
    
        Barmar
        
- 741,623
- 53
- 500
- 612
 
    
    
        Victor Nduonyi
        
- 1
- 1
- 
                    Please show your regexp that doesn't work. – Barmar Jul 27 '22 at 22:09
1 Answers
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