In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How to add a dash to SOME zip codes only

vmirand
6 - Meteoroid

Hello. I am trying to add a dash to the zip codes with a length of more than 5 NUMERIC characters only. Also, I have zip codes of 6 characters (letters and numbers) that I am not looking to edit. Can somebody please help me with a formula that meets those conditions?

 
Zip codeResult
98604485098604-4850
7993679936
56465426256465-4262
R2X1G7R2X1G7

 

Thank you

2 REPLIES 2
DataNath
17 - Castor
17 - Castor

Hey @vmirand, there's a few ways to go about this - here's what I've quickly put together:

 

1717.png

 

Formula expression:

 

IF REGEX_Match([Zip code], '\d{6,}')
THEN REGEX_Replace([Zip code], '(.{5})(.*)', '$1'+'-'+'$2')
ELSE [Zip code]
ENDIF

 

Without RegEx you could use standard functions to do something like:

 

 

IF Length([Zip code]) > 5 AND IsInteger([Zip code])
THEN Left([Zip code], 5) + '-' + Right([Zip code], Length([Zip code])-5)
ELSE [Zip code]
ENDIF

 

 

vmirand
6 - Meteoroid

Thank you much @DataNath ! It worked.

Labels
Top Solution Authors