cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
shanemeisner
Level 8

ismatch and canada zip code

I have a form where Vendors can be from the US or Canada and we need to validate users are entering the correct Zip Code format.
For US I was able to get this formula to work correctly:

If( IsMatch(VenZip.Text, Digit & Digit & Digit & Digit & Digit) Or IsMatch(VenZip.Text, Digit & Digit & Digit & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit), Gray, Red)

But, per the subject of the post, for canada I also need to validate the Zip Code.
Using the site: http://www.regexlib.com/Search.aspx?k=zip I found the following expression that is for US and Canada: ^((\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d))$
which I was hoping would work, but so far no luck.. I tried:
If( IsMatch(VenZip.Text, "\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d", MatchOptions.Contains) , Gray, Red) &
If( IsMatch(VenZip.Text, "\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]", MatchOptions.Contains) , Gray, Red)
Both give me an error of:
The provided regular expression is invalid: SyntaxError: Invalid regular expression: /\ my code..... : Unmatched ')'canadazippng.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
EricLott
Level 10

Re: ismatch and canada zip code

Try this:

If(IsMatch(VenZip.Text,"^((\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d))$",MatchOptions.Complete),Gray,Red)

It's working on my end

2020-01-09 15_35_53-SQLQuery111.sql - ubpos02_liberty.INVENTORYSCAN (OWENSGROUP_elott (64))_ - Micro.png

View solution in original post

3 REPLIES 3
EricLott
Level 10

Re: ismatch and canada zip code

Try this:

If(IsMatch(VenZip.Text,"^((\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d))$",MatchOptions.Complete),Gray,Red)

It's working on my end

2020-01-09 15_35_53-SQLQuery111.sql - ubpos02_liberty.INVENTORYSCAN (OWENSGROUP_elott (64))_ - Micro.png

View solution in original post

Super User
Super User

Re: ismatch and canada zip code

@shanemeisner 

Rather than use the code you found online I would suggest this since its simpler to understand what going on.  Canadian postal codes follow the pattern A0A 0A0 where A is a letter and 0 is a number.

 

If(IsMatch(VenZip.Text, Letter & Digit & Letter & Space & Digit & Letter & Digit), Gray, Red)

 

Source: I live in Canada, LOL

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up." 

shanemeisner
Level 8

Re: ismatch and canada zip code

Worked perfectly  can enter 56789 or 56789-3456 or P0X 1K0 and they all work.. Any other format gives me the "RED" border error.

THANKS!!!!

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,609)