我知道还有其他类似的问题,但我反正问,我试图验证一个邮政编码只有数字输入,名称只有输入字母。我尝试了一些isNaN,但那并不奏效。这里是代码即时尝试验证。javascript verify是一个数字或唯一的字母
if(first_name.length < 2){
alert("Please enter your first name.");
return false;
}else if(zip=="" || zip.length < 5){
alert("Please enter a valid zip code.");
return false;
我tryed像这样
}else if(zip=="" || zip.length < 5 || zip == isNaN){
alert("Please enter a valid zip code.");
return false;
是'/ [a-zA-Z] + /。test(letters_only_string)'和'/ \ d + /。test(num_only_string)'不够好吗? – Chad 2013-03-11 21:24:52
不要问! – gdoron 2013-03-11 21:24:53
对这样的东西使用正则表达式。 – kinakuta 2013-03-11 21:25:05