We accept safe and secure Credit Card and PayPal Payments.
 
Perl Scripts

All Count
Attachment Mailer
Perl Scripts Build A FAQ Plus
Perl Scripts Clock In Center
eBackup Automated
Easy Poll
eSurvey
Fetch a File
Form Maker
Mailing List Server
MySQL Mate
PDF Creation
QCart
Quick Fix
Quote of the day
Speed Search
Task Manager
Traffic Pack
Upload Plus
Upload Gold
Upload Pro
Website Manager

 
Free Perl Downloads

Free Perl Scripts Main Page
Free Perl Scripts 404 Alerter
AccessLog Viewer
Build A FAQ
PHP Scripts eBackup
Free PHP Scripts ErrorLog Viewer
eVars - Server Info
HT Pass Creator
Upload Lite
Website Manager

 
JavaScripts

Free Java Scripts Alert Boxes
Free JavaScripts Browser Sniffer
Check email
Generators
Slide Show
Sudoku
Window Maker
More...

 
Extra Utilities

ASP Scripts Ascii Codes
Free ASP Scripts Color Picker
Font Finder
HT Pass Creator
Meta Cloak
Meta Magic
Pano Zooms
SlideShow
Server Size

 
Online Tutorials

Free HTML Scripts Glossary
Free HTML Scripts HTML
JavaScript
MySQL
SSI
Build Traffic
Other

 
Miscellaneous

About Us
Graphics
Testimonials
Installations
Latest versions

 
Hawk Eye in Tennis

Should Hawk Eye replace linesmen and lineswomen at all tennis tournaments?







 
View all Polls

Run Polls on your site

Run your own Surveys

 
Store Download FAQs Contact Us Support Programming Policies  
JavaScripts :: Detectors :: Zip Code Validator

This javascript checks the length of a zip or post code entered into a form and if the length is equal to 9 numeric characters will then format it with a hyphen inserted after the 4th character. Suitable for validating US postal codes only. Users may enter alpha characters or non numeric characters in the zip code such as hyphens and or spaces. The Javascript will remove all non numeric charcters and return the formated zip code.

Simply copy the function to your web document, then call the function in your form validation.

The Script

<script>
<!--
/* Copyright http://www.perlscriptsjavascripts.com 
Free and commercial Perl and JavaScripts        */

function checkZip(z){
	if(document.images){
		z.value = z.value.replace(/\D+/, "");
	}
	if(z.value.length != 5 && z.value.length != 9){
		alert("Whoops, please check your zip code");
		if(document.all || document.getElementById){
			z.style.background = "yellow";
		}
		z.focus();
		return (false);
	}
	if(z.value.length > 5){
    z.value = z.value.substr(0,5) + "-" + z.value.substr(5);
	}
	return (z.value);
}
// -->
</script>

Usage

Inside your existing form validation script, you'd use the following code to call the zip code validation function. If the zip code entered by the user has an invalid length after non numeric characters are removed, and alert message will pop up. Here is an example form validation script and it's form.

<script>
<!--
function checkForm(f){
	if(!checkZip(f.zip)){
		return false;
	} else {
		f.zip.value = checkZip(f.zip);
	}
}
// -->
</script>

<form onsubmit="return checkForm(this);">
<input type="Text" name="zip">
<input type="Submit" value="Check">
</form>

The code below combines both functions and the sample form so you may test the script in real time. Simply copy and paste all code in to any web page.

Select All   De-select
Speed Search our site
Survey Software
Create unlimited web based surveys on your website from your website

Linux Hosting Plans from $9.12 per month, includes Plesk Control Panel, MySQL databases, cgi-bin, crontab manager and 50 email accounts.

Discounted Scripts
Subscribe to our periodial newsletter to receive special offers.

Bathroom Hygiene
How often do you thoroughly clean your bathroom?








View all Polls

Run Polls just like this one on your website!


About us | Contact us | Script FAQs | Script Support | Website Hosting | Our Policies | Store | Testimonials
Subscribers log in here. Subscribe to our periodical newsletter for special offers on commercial scripts, hosting, exciting business opportunities, and industry news and events. Our Mailing List Software is powered by Consolidator    
HTML Plain text
©1999 - 2015 All content Copyright PerlScriptsJavaScripts.com Proudly hosted by LinuxHostingPlans.com