The Alteryx Community is a finalist in three 2026 CMX Awards! Help us win Customer Support Community, Most Engaged Community, and User Group Program of the Year - vote now! (it only takes about 2 minutes) before January 9.
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. 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