vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   REGEX Question (https://vborg.vbsupport.ru/showthread.php?t=172769)

Antivirus 03-12-2008 12:58 AM

REGEX Question
 
I've been trying to write a REGEX to handle either US or Canadian zip codes. US Zipcodes is easy, however how do I validate a canadian zip code, and is it possible for the regular expression to check that the entered data is either US or Canadian format?

Format for US zipcodes is 5 characters, numbers only - therefore my regex for US zipcodes is: /^[0-9]{5}$/

Format for CANADA zipcodes is a little more complex, (# = number, and L = letter) and like this: 3 digits (format L#L) then a space then another 3 digits (#L#). Anyone able to get this done, and is it possible to do it with an OR therein?

This is to be used in vbulletin custom user profile field.
Thanks:)

Adrian Schneider 03-12-2008 01:19 AM

This worked for me...
Code:

'/^([a-z]{1})([0-9]{1})([a-z]{1}) ([0-9]{1})([a-z]{1})([0-9]{1})$/i'

Antivirus 03-12-2008 02:31 AM

works for me as well, but is it possible to use that along with the other one to check that the data fits one or the other?


Something like this:

^[0-9]{5}$ OR ^([a-z]{1})([0-9]{1})([a-z]{1}) ([0-9]{1})([a-z]{1})([0-9]{1})$

This doesn't seem to be working.

--------------- Added [DATE]1205350730[/DATE] at [TIME]1205350730[/TIME] ---------------

Sir, yours worked on it's own, thanks. I found this site that provided the following regex which works, for either US or CAN as needed.

^(\d{5}-\d{4}|\d{5})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)$

thanks!

--------------- Added [DATE]1205362842[/DATE] at [TIME]1205362842[/TIME] ---------------

ok, so one more thing which I am trying to add to it and i cannot for the life of me figure it out... the current regex is:

^(\d{5})$|^([A-Z]\d[A-Z] \d[A-Z]\d)$|^(other)$

what i need to also check is that the US zipcode is not equal to 00000
anyone know?

Adrian Schneider 03-14-2008 09:21 AM

Code:

and $zipcode != '000000'
lol :)


All times are GMT. The time now is 07:10 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01703 seconds
  • Memory Usage 1,716KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete