2 回答

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超6個(gè)贊
var theInput = document.getElementById("temp");
var regex = /(?:[A-Za-z].*?\d|\d.*?[A-Za-z])/;
theInput.addEventListener("keyup", function () {
if(theInput.value.length == 0){
console.log("Is empty");
} else if(!!theInput.value.match(regex)){
console.log("Both number and characters");
} else if(theInput.value.length > 0 && !isNaN(theInput.value)){
console.log("Number");
} else {
console.log("NOT a Number");
}
});
<input id="temp" type="text">

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊
var value = document.getElementById("temp").value;
if(value.length > 0 && !isNaN(value))
{
//code
}
添加回答
舉報(bào)