我编写了一些 javascript 来验证字符串是否为字母数字,但我只是想知道如何添加一些代码以包含连字符(-)和斜杠(/)作为可接受的输入。这是我当前的代码:
function validateAddress() {
var address = document.getElementById('address');
if (address.value == "") {
alert("Address must be filled out");
return false;
} else if (document.getElementById('address').value.length > 150) {
alert("Address cannot be more than 150 characters");
return false;
} else if (/[^a-zA-Z0-9\-\/]/.test(address)) {
alert('Address can only contain alphanumeric characters, hyphens(-) and back slashs(\)');
return false;
}
}