Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2012, 06:15 PM   PM User | #1
jswannabe
New Coder

 
Join Date: Nov 2012
Location: Canada
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
jswannabe is an unknown quantity at this point
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>
jswannabe is offline   Reply With Quote
Old 12-03-2012, 07:21 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
<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".
WolfShade is offline   Reply With Quote
Old 12-03-2012, 11:51 PM   PM User | #3
jswannabe
New Coder

 
Join Date: Nov 2012
Location: Canada
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
jswannabe is an unknown quantity at this point
Sa-weet! Thank you!
jswannabe is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:28 AM.


Advertisement
Log in to turn off these ads.