Reply
zip error checking
Old 07-06-2005, 04:56 AM zip error checking
The_Anomaly's Avatar
Extreme Talker

Posts: 201
Location: Boston, Ma
I wrote this small thing to check to make sure a zip code was valid. correct leingth, no letters, etc. The small problem is that when someone enters a zip starting with a zero it gives the onblur "your zip is too short" message. Anyone know how i could test an int that starts with a zero and not have the browser think its only 4 digits? I was either thinking of keeping it a string and checking for 5 characters, but i'm not really sure how to do that. the code i have now is:

Code:
function zipCheck(x)
{
         myInt = x.value;


			if ((myInt + 1)>0)
			{  
                           if (myInt < 10000)
                           {
                           alert("Your number wasnt long enough");
                           }
                        }

			else{  alert("That is not a valid zip code");  }

}
__________________
Forum Admin (taking no credit for design): http://rsfreedom.com/
The_Anomaly is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 07-06-2005, 08:56 AM
chrishirst's Avatar
Super Moderator

Posts: 12,649
Location: Blackpool. UK
you could use a regular expression.
this checks for the value having 5 digits or starting with 5 digits followed by a hyphen (-) then 4 digits

Code:
function isZipCode(value) {
   var RegExp = /^\d{5}([\-]\d{4})?$/;
   return (RegExp.test(value));
}
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-07-2005, 04:13 PM
The_Anomaly's Avatar
Extreme Talker

Posts: 201
Location: Boston, Ma
o poo, i hate reg expressions. they confuse me to the 10th degree
__________________
Forum Admin (taking no credit for design): http://rsfreedom.com/
The_Anomaly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to zip error checking
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12304 seconds with 13 queries