假设我有以下 JS 代码,我只能在收到不可接受的字符时删除整个字符:
function checkInput() {
document.getElementById("message").setAttribute('maxlength', (456));
for (var i = 0; i < document.fr_upload.message.value.length; i++) {
if (!checkLatin(document.fr_upload.message.value)) {
alert("Your entry does not contain latin type.\n Please try again.")
document.fr_upload.message.value = '';
document.fr_upload.char_left.value = 0;
return false;
}
}
}
function checkLatin(arg) {
var latin = /^[\u0020-\u007E]*$/;
if (arg.match(latin)) {
return true;
} else {
return false;
}
}
因此,我怎样才能只删除不可接受的字符?