Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Javascript alphanumeric postal code Not checking !

Posted on 2013-06-03
8
296 Views
Last Modified: 2013-06-06
Hi experts,

I'm looking for javascript alphanumeric postal code validate in my list of array postalcode only.. I attached in my sample code, but it not checked alphanumeric value only checking numeric value.. Plz guide me what mistake in my code..

Thanks,
test-zipcode.html
0
Comment
Question by:codeoxygen
  • 4
  • 4
8 Comments
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39216563
Code seems fine if you want to check for postal codes that are exactly 5 digits long but you said alpha-numeric postal codes.

Your regular expression is only checking for digits - not alphas.

What are the possible inputs with respect to your postal codes that you want to validate for?
0
 

Author Comment

by:codeoxygen
ID: 39217943
Example : var codes = ["SO15 0HX","SO15 0HY"];

i want to check only two alphanumeric postal code only ("SO15 0HX","SO15 0HY").

1. if enter code contain only numeric or only letters
{ alert("Postal code not valid") }
2. Or enter alphanumeric either of correctly ("SO15 0HX","SO15 0HY") go to other page..
3. Or enter alphanumeric is wrong of (ex. S015 00X) {alert ("postal code is not found").

How i make that possibilities in my code?
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39218148
So are there only two correct postal codes?

If this is the case why not have a radio button or drop down for this selection or have a check

if (postal_code != "SO15 0HX" && postal_code != "SO15 0HY") ...

Or are there potentially other valid codes?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:codeoxygen
ID: 39218255
No. i check "n" number of postal code  in that array of like
var codes = ["SO15 0HX","SO15 0HY","",......];
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39218297
If they are fixed then why not have them in a drop down?
0
 

Author Comment

by:codeoxygen
ID: 39218353
It's fixed  but 400 + postal code want to check. so dropdown goes to lengthy., so i'm looking to checking list of array fixed value's using javascript? it's possible..
0
 

Author Comment

by:codeoxygen
ID: 39218583
http://jsfiddle.net/Wgrtv/

i got a solution here..
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39218648
Yes that will work - in future describe your problem a bit better - the problem as presented was using a regular expression with no mention of an array of postal codes. By giving more information you can help experts give you the answer you need quicker.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question