How to check whether the string contain only letters and numbers in JavaScript

2 Answers

0 votes
var s = "javascript123";

if (/^[a-zA-Z0-9]*$/.test(s) === false) {
    document.write("false");
} else {
    document.write("true");
}


/*
run:
  
true 
     
*/

 



answered Sep 17, 2019 by avibootz
0 votes
var s = "javascript - 123";

if (/^[a-zA-Z0-9]*$/.test(s) === false) {
    document.write("false");
} else {
    document.write("true");
}


/*
run:
  
false 
     
*/

 



answered Sep 17, 2019 by avibootz
...