I have the following functions
JavaScript
function lettersNumbersOnly(string){
if (/[A-Za-z0-9]/.test(string)) {
console.log('Clean');
}else{
console.log('Not Matching');
}
}
$(".test-input").change(function(){
lettersNumbersOnly($(this).val());
});
If I were to put letters and numbers into that .test-input
field, I get the "Clean"
. BUT if I put characters like !2@$%
etc. I still get the "Clean"
which is not what I want. I just want strictly letters and numbers. Any suggestions?