Problem with regexp, replace and ToUppercase in JS validation
<p>I am trying validate a Quebec postal code before a form is submitted. The following function (onBlur) is supposed to make the letters uppercase and remove any white space. Everything before the "else" works fine. </p>

<pre><code>function back2(that){
    if (that.value.length &lt;=4) {
        that.value = that.getAttribute("default");
        that.setAttribute("class", "exemple");
    } else {
        if (that.getAttribute("id") == 'zip') {
            that.setAttribute("value", that.value.replace(/\s/g, ""));
            that.setAttribute("value", that.value.toUpperCase());
        }
    }
}
</code></pre>

<p>This is part of the form validation code triggered by an onSubmit event: </p>

<pre><code>    if (f.value != "^G//d//D//d//D//d$" || 
        f.value != "^H//d//D//d//D//d$" ||
        f.value != "^J//d//D//d//D//d$" ||
        f.value != "^K1//D//d//D//d$" ||
        f.length !=6 ) {
        alert("Veuillez mettre un code postal valide du Québec, merci.");
        return false;
    }
    return true;
}
</code></pre>

<p>and HTML code:</p>

<pre><code>&lt;td&gt;Code Postal&lt;/td&gt;
&lt;td&gt;&lt;input name="zip" type="text"
     id="zip" value="J0B4M1" size="35"
     class="exemple" onfocus="clean(this)"
     onblur="back2(this)" default="J0B4M1"&gt;&lt;/td&gt;
</code></pre>

<p>There are problems in both parts of JS code because nothing happens when I change field boxes and the postal code has spaces and is in lowercase letters. Also, I get an alert even if the format of the postal code is correct. Help!</p>
