<script language="javascript" type="text/javascript">
<!--
function check(){
var strpost=document.getElementById("tbPost");
if(strpost!=""||strpost!=null)
{
strpost=strpost.match(^[1-9]\d{5}$);
if(strpost==null)
{
alert('请输入正确的邮政编码!!');
return false;
}
} } //-->
</script><form id="form1" runat="server" onsubmit="javascript:return check()">当我执行的时候老是提示我说语法错误?问题出在哪?
<!--
function check(){
var strpost=document.getElementById("tbPost");
if(strpost!=""||strpost!=null)
{
strpost=strpost.match(^[1-9]\d{5}$);
if(strpost==null)
{
alert('请输入正确的邮政编码!!');
return false;
}
} } //-->
</script><form id="form1" runat="server" onsubmit="javascript:return check()">当我执行的时候老是提示我说语法错误?问题出在哪?
因该传入的参数是字符串吧???
<!--
function check(){
var strpost=document.getElementById("tbPost");
if(strpost.value!=""||strpost.value!=null)
{
strpost.value=strpost.value.match(/^[1-9]\d{5}$/);
if(strpost.value=="null")
{
alert('请输入正确的邮政编码!!');
return false;
}
} } //-->
</script>
return reg.test(strpost);
修改成
strpost=strpost.match("^[1-9]\\d{5}$");
看看。
strpost=strpost.match(rule);