Form validation - UK postcode

This is a discussion on "Form validation - UK postcode" within the JavaScript Forum section. This forum, and the thread "Form validation - UK postcode are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 24th, 2008, 16:05
Junior Member
Join Date: Sep 2007
Location: UK
Age: 20
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Form validation - UK postcode

Hi i need js validation for my form, iv done everything except validation for a UK postcode, iv had a look on the net, but all the examples seem pretty complicated. Can anyone help?
Reply With Quote

  #2 (permalink)  
Old Mar 5th, 2008, 21:08
Junior Member
Join Date: Mar 2008
Location: Torquay, Devon, UK
Age: 23
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form validation - UK postcode

Hi. Here's a little checker using a RegEx which complies with all BS 7666 postcode format rules. I used this a while on a JS validated form. Enjoy!

Code: Select all
function val(){
if((document.getElementById("txtPostCode").value.toUpperCase().match(/GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]) [0-9][ABD-HJLNP-UW-Z]{2}/))){return true;}else{return false;}
}
Replace "txtPostCode" with the id of your post code field. (duh!)

Sincerely,
Rob Hardy
Reply With Quote
Reply

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
AS Form / Validation Help papalazarou78 Flash & Multimedia Forum 0 Jul 31st, 2007 19:43
Form Validation cjrollo Flash & Multimedia Forum 0 Feb 22nd, 2007 17:33
Form Validation feebee JavaScript Forum 1 Aug 3rd, 2006 16:12
PHP Form Validation ??? j4mes_bond25 PHP Forum 2 May 31st, 2006 23:08
Form validation brittny JavaScript Forum 2 Jul 8th, 2005 19:46


All times are GMT. The time now is 05:46.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43