Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 216
Location: Boston, Ma
Trades: 0
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");  }

}
The_Anomaly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-06-2005, 09:56 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-07-2005, 05:13 PM
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
o poo, i hate reg expressions. they confuse me to the 10th degree
The_Anomaly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to zip error checking
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
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.11663 seconds with 12 queries