function ComMethod() 
{     
    var PARAMETERSPOSTCODE = /^[1-9]{1}[0-9]{5}$/;  //邮编     
}ComMethod.prototype.CheckPostCode = function (str) {
    with (this) {
        if (PARAMETERSPOSTCODE.test(str))
            return true;
        return false;
    }
}
这样写不行啊
<body>
 <input type="text" id="mail"/>
 <input type="button" value="验证" onclick="ComMethod.prototype.CheckPhoneNumber(mail.value)" />
</body>

解决方案 »

  1.   

    看不懂!PARAMETERSPOSTCODE 应该都没值才对 ComMethod 又没return 也不是全局。真没见过这么诡异的写法。
      

  2.   


     if (!PARAMETERSPOSTCODE.test(str))
      return true;
      return false;
      

  3.   

    匹配中国邮政编码:[1-9]\d{5}(?!\d)
    评注:中国邮政编码为6位数字function checkNum(obj)
    {
    var re = [1-9]\d{5}(?!\d);
    if (!re.test(obj.value))
    {
    alert("邮编不对!");
    obj.value="";
    obj.focus();
    return false;
    }
    return true;
      

  4.   

    话说这两个方法不同吧。
    ComMethod.prototype.CheckPhoneNumber
    ComMethod.prototype.CheckPostCode//要调用到这个方法吧
    ComMethod.prototype.CheckPostCode = function (str) {
    alert("我被触法了");