PDA

View Full Version : Verification of Postal Code only


Crash1hd
08-14-2002, 01:34 PM
ok I was searching the thread and I found a post in regards to doing a verification check on postal codes and zip codes the only problem is I dont understand it very well and cant change it to just do the postal code the site Im working on is a canadian site and needs a postal code verification only so I was wondering if there was anyone out there that could explain how to make one or had a script of one that works

the postal code is being entered into a text box in the form under the name of PostalCodeField

Thanks In Advance

Squintz
08-14-2002, 01:36 PM
Post the code you have and let us work from that...

Crash1hd
08-14-2002, 01:44 PM
Ok The script I had found was posted by whammy and it is

var vzip1 = /^\D*(\d{5})$/
var vzip2 = /^\D*(\d{5})\D*(\d{4})\D*$/
var vpostcode = /^\W*([a-z]{1}\d{1}[a-z]{1})\W*(\d{1}[a-z]{1}\d{1})\W*$/i
/* Format US/Canadian Postal Code */
function formatzippostal(zip){
if(vpostcode.test(zip.value)){
zip.value = zip.value.toUpperCase();
zip.value=zip.value.replace(vpostcode,'$1 $2');
}
else if(!vzip1.test(zip.value)){
if(vzip2.test(zip.value)){
zip.value=zip.value.replace(vzip2,'$1-$2');
}
}
}


however all my other validations have been like so

function CheckSubmit()
{
{
if (document.mailform.first_name.value == "" | document.mailform.last_name.value == "")
{
alert("You missed one of the Name fields please recheck and resubmit.")
return
}
document.mailform.submit()
}

and as stated before the text box for the postal code is

<input id"postalcodefield" maxLength="100" name="PostalCodeField" size="17">

so that is what I have but the script given by whammy I dont understand how it works mostly the part i dont understand is the following maybe if someone explained it i might be able to understand it better

var vzip1 = /^\D*(\d{5})$/
var vzip2 = /^\D*(\d{5})\D*(\d{4})\D*$/
var vpostcode = /^\W*([a-z]{1}\d{1}[a-z]{1})\W*(\d{1}[a-z]{1}\d{1})\W*$/i

I understand what Var are but the stuff behind the = sign why that perticular code and not something else is what I dont understand

Thanks

Squintz
08-14-2002, 01:59 PM
I dont understand exactly what they mean but i can tell you that thats a varialble holding the format that the postal code should be in....

now im not sure if this will work because iv only ready tutorials on JS i never actually use them but my reading the above code this is what i cam up with

var vpostcode = /^\W*([a-z]{1}\d{1}[a-z]{1})\W*(\d{1}[a-z]{1}\d{1})\W*$/i

/* Format Canadian Postal Code */
function formatzippostal(zip){

if(vpostcode.test(zip.value)){
zip.value = zip.value.toUpperCase();
zip.value=zip.value.replace(vpostcode,'$1 $2');
}

else {
/* What you want it to do if it does not check out*/
}
}
}


Sorry if this doesnt work i am only trying to help...like i said tho i never actually used java but have ready pleny of toots