/    Sign up×
Community /Pin to ProfileBookmark

Post Code Checker

Hi team,

I have a project of Laundry dry cleaning where they collect clothes from customers and after service deliver to them. I have made the website but stuck with the postcode part where client has to enter his postcode and get the message that his area is not covered else the customer has to be redirected to the price list page.

I have the code for validating postcodes but need help how to set up a code where I can tell customers that they are not covered after having specific postcodes in my coverage area database.

Thanks in advance.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@rootJan 25.2017 — Please don't double post, if you have something to add, edit the post or add a further comment to your post.

http://www.webdeveloper.com/forum/showthread.php?361355-Post-Code-Checker
Copy linkTweet thisAlerts:
@mrfakeJan 26.2017 — There's a number of ways to do this. Which back end tools are you using? (tools for me means: Language, stack, libraries, frameworks, external memory caches or database implementation, etc.)

If you are only working with front end code, you might want to look for an automated emailing/texting site that has an API for developers, and use AJAX requests to communicate with the site you find, to send emails and texts.
Copy linkTweet thisAlerts:
@mrfakeJan 26.2017 — There's a number of ways to do this. Which back end tools are you using? (tools for me means: Language, stack, libraries, frameworks, external memory caches or database implementation, etc.)

If you are only working with front end code, you might want to look for an automated emailing/texting site that has an API for developers, and use AJAX requests to communicate with the site you find, to send emails and texts.[/QUOTE]


Actually don't do this! I forgot you'll have to expose any oauth keys or tokens generated for use on the site's api - which to sum up it extremely risky, don't do it! I wish I edit that post. Anyways, you'll need some ability to create/modify server side code.
Copy linkTweet thisAlerts:
@rootJan 26.2017 — When checking a post code, just send the postcode to the server with an AJAX request that returns a simple true / false result.

The user doesn't need to be logged in, no exposing anything about the server.
Copy linkTweet thisAlerts:
@evoluerJan 27.2017 — Hey hi pardes5,

Had a look at the example site, but need more details from your side. eg: what framework have you used?, which part of your workflow depends on this? should this be client side or server side?

Please do answer the above, i will be needing more details as well. You can also contact me at [email][email protected][/email] to discuss this in detail
Copy linkTweet thisAlerts:
@pardes5authorJan 31.2017 — When checking a post code, just send the postcode to the server with an AJAX request that returns a simple true / false result.

The user doesn't need to be logged in, no exposing anything about the server.[/QUOTE]


Good idea... but what If I want my user to enter my site with the specific postcodes that are covered in my delivery area.???
Copy linkTweet thisAlerts:
@rootJan 31.2017 — Good idea... but what If I want my user to enter my site with the specific postcodes that are covered in my delivery area.???[/QUOTE]

Thats the point, you send a query via AJAX, the serverside script queries your postcode database, the result returned can be a simple true or false so that your JavaScript can act accordingly.

It would be better that your postcode database that you use has a datafield that you can update as and when needed to indicate that road or postcode district is covered, some areas are dense enough to simply say that we cover all that area.

What PC database are you using? Did you get it from the post office or from an open source? I ask because I have tried both routes in the past and while open source is reasonably accurate, only the postal office is 100% up to date with their data.

Using an HTML5 input: [code=html]
<input name="postcode" type="text" value="" placeholder="AB1 2AZ" pattern="^[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}$" >[/code]


the field will do a basic validate for a post code, an actual regexp for covering real postcodes would be near on impossible to produce, so a basic postcode format is sought. This data can then be passed to the server, it could be an AJAX call based on the focus moving way from the field. For example
[code=html]
<input name="postcode" type="text" value="" placeholder="AB1 2AZ" pattern="^[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}$" onblur="postcodeAJAX(this);" >[/code]
where your postcodeAJAX(this) will call your main AJAX validation routine with the server via AJAX when the onblur event is triggered by moving focus to the next field.

Note that you do have to have the inputs in a <form> for the field validation to work using the regular expression in the pattern attribute. If you use an AJAX call triggered by an onblur event, the validation with the server still happens via the server as the AJAX function you call will run independently of the web form and any validation in place.
×

Success!

Help @pardes5 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...