正则表达式只允许小写字符和数字

时间:2021-04-18 15:38:44

标签: javascript regex string dom

我正在尝试验证输入。我只想要小写字符和数字。我的正则表达式是:/^[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');
    }
}

0 个答案:

没有答案