zipcode
if (document.regform.u_zipcode.value == ""){
alert ("提示: 必须输入邮编!");
document.regform.u_zipcode.focus();
return false;
}
if (document.regform.u_zipcode.value.length!=6){
alert ("提示: 邮编长度不正确!");
document.regform.u_zipcode.focus();
return false;
}
bstring = "0123456789";
for(i = 0; i < document.regform.u_zipcode.value.length; i ++)
{
if (bstring.indexof(document.regform.u_zipcode.value.substring(i,i+1))==-1)
{
alert('邮编 只能包含数字及-*');
document.regform.u_zipcode.focus();
return false;
}
}
实例说明
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
</head><body>
<form id="form1" name="regform" method="post" action="">
<label>
输入邮编:
<input type="text" name="u_zipcode" />
</label>
<label>
<input type="submit" name="submit" value="验证" onclick="checkzip();"/>
</label>
</form>
</body>