我正在尝试验证输入。我只想要小写字符和数字。我的正则表达式是:/^[a-z0-9]+$/ 但它不起作用。
我的代码是:
let input1 = document.getElementById('input1');
const regex = new RegExp('/^[a-z0-9]+$/');
function validate() {
if (regex.test(input1.value)) {
console.log('ok');
}
else {
console.log('not ok');
}
}