本文介绍了在 JavaScript 中检查字母数字的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对 JSP
中的 INPUT
字段执行字母数字检查的最佳方法是什么?我附上了我当前的代码
What is the best way to perform an alphanumeric check on an INPUT
field in JSP
? I have attached my current code
function validateCode() {
var TCode = document.getElementById("TCode").value;
for (var i = 0; i < TCode.length; i++) {
var char1 = TCode.charAt(i);
var cc = char1.charCodeAt(0);
if ((cc > 47 && cc < 58) || (cc > 64 && cc < 91) || (cc > 96 && cc < 123)) {
} else {
alert("Input is not alphanumeric");
return false;
}
}
return true;
}
推荐答案
您可以使用 这个正则表达式 /^[a-z0-9]+$/i
这篇关于在 JavaScript 中检查字母数字的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!