Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2012
    Location
    Canada
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Canadian Postal Code Validation

    Help me add an Auto Tab please.

    Code:
    <!DOCTYPE HTML>
    
    
    <html>
    <head>
    <title></title>
    <link rel="stylesheet" href=".css">
    </head>
    
    <script>
    
    
    function checkfsa () 
    {
    var getfirst3 = document.getElementById("fsa").value;
    var getlast3 = document.getElementById("ldu").value;
    var check1 = new RegExp ("d", "i");
    var check2 = new RegExp ("f", "i");
    var check3 = new RegExp ("i", "i");
    var check4 = new RegExp ("o", "i");
    var check5 = new RegExp ("q", "i");
    var check6 = new RegExp ("u", "i");
    var check7 = new RegExp ("^\\d");
    var check8 = new RegExp ("\\d{2}");
    var check9 = new RegExp ("^\\D", "i");
    var check10 = new RegExp ("\\D{2}", "i");
    var check11 = new RegExp ("^[W]", "i");
    var check12 = new RegExp ("^[Z]", "i");
    var warning1 = "There are no 'd's in Canadian Postal Codes";
    var warning2 = "There are no 'f's in Canadian Postal Codes";
    var warning3 = "There are no 'i's in Canadian Postal Codes";
    var warning4 = "There are no 'o's in Canadian Postal Codes";
    var warning5 = "There are no 'q's in Canadian Postal Codes";
    var warning6 = "There are no 'u's in Canadian Postal Codes";
    var warning7 = "Letter|Number|Letter format for first 3 digits of Canadian Postal Codes";
    var warning8 = "Number|Letter|Number format for the last 3 digits of Canadian Postal Codes";
    var warning9 = "Canadian Postal Codes do not start with a 'w'";
    var warning10 = "Canadian Postal Codes do not start with a 'z'";
    if (check1.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning1;
    }
    if (check2.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning2;
    }
    if (check3.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning3;
    }
    if (check4.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning4;
    }
    if (check5.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning5;
    }
    if (check6.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning6;
    }
    if (check7.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning7;
    }
    if (check8.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning7;
    }
    if (check11.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning9;
    }
    if (check12.test(getfirst3))
    {
    document.getElementById("warning").innerHTML = warning10;
    }
    if (check1.test(getlast3))
    {
    document.getElementById("warning").innerHTML = warning1;
    }
    if (check2.test(getlast3))
    {
    document.getElementById("warning").innerHTML = warning2;
    }
    if (check3.test(getlast3))
    {
    document.getElementById("warning").innerHTML = warning3;
    }
    if (check4.test(getlast3))
    {
    document.getElementById("warning").innerHTML = warning4;
    }
    if (check5.test(getlast3))
    {
    document.getElementById("warning").innerHTML = warning5;
    }
    if (check6.test(getlast3))
    {
    document.getElementById("warning").innerHTML = warning6;
    }
    if (check9.test(getlast3))
    {
    document.getElementById("warning").innerHTML = warning8;
    }
    if (check10.test(getlast3))
    {
    document.getElementById("warning").innerHTML = warning8;
    }
    
    }
    
    
    
    </script>
    
    
    <body>
    
    Postal Code:
    <input type="text" maxlength=3 size=3 id="fsa" onkeyup="checkfsa ();">
    <input type="text" maxlength=3 size=3 id="ldu" onkeyup="checkfsa ()">
    
    <!--fsa means Forward Sorting Area. ldu means Local Delivery Unit -->
    
    <div id="warning"></div>
    
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    <input type="text" maxlength=3 size=3 id="fsa" onkeyup="checkfsa ();if(this.value.length == 3){document.getElementByIdI('ldu').focus();}">
    <input type="text" maxlength=3 size=3 id="ldu" onkeyup="checkfsa ()">
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    New Coder
    Join Date
    Nov 2012
    Location
    Canada
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sa-weet! Thank you!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •