The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
![]()
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 ![]() |
#2
|
||||
|
||||
![]()
This worked for me...
Code:
'/^([a-z]{1})([0-9]{1})([a-z]{1}) ([0-9]{1})([a-z]{1})([0-9]{1})$/i' |
#3
|
||||
|
||||
![]()
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? |
#4
|
||||
|
||||
![]() Code:
and $zipcode != '000000' ![]() |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|