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.
解決済み

Data validation to check character types in string field - letters, numbers and hyphens

jt_edin
アステロイド

I need help from someone more experienced please to quickly point out the most concise or elegant way (perhaps regex?) to validate a field based on its character types. I want to validate that my field contains only letters (A to Z), digits (0 through 9), and only the character "-" (a hyphen).

 

If the field contains any other punctuation (eg underscore, period, comma) I want it to fail the test.

 

So I'm looking for a filter or regex tool to do the above, and I think someone will know better than me! Thanks

5件の返信5
LordNeilLord
オーロラ

Hey @jt_edin 

 

In the formula tool you could use a custom filter with regex like this:

 

[Field1] = RegEx_Replace(Field1, "[^\w-]","")

 

The regex part [^\w-] means anything that isnt a alphanumeric character (\w) and a hypen (-)

 

rfilter.PNG

jt_edin
アステロイド

Thanks. Is this a Filter tool or a Formula tool? How would I embed that within a Regex Match instead?

 

And, how did you get it to work without brackets [ ]  around Field1? Would it be possible to post the workflow please? Thanks!

jt_edin
アステロイド

Is anyone else able to clarify how to implement the solution kindly offered by @LordNeilLord ? Thanks

LordNeilLord
オーロラ

Hey @jt_edin 

 

I used a filter tool to do this, regex_match would be almost exactly the same, something like Regex_match(Field1, "[^\w-]") 

 

In Alteryx, if there is no space in the column header you do not always need to use the [] around the name. 

 

Neil

monsieursnow
アトム

Hello

I faced a similar problem and I found my own method: Formula Tool.

I didn't use Regex, but instead I used the STRSPN function

 

If STRSPN([Field1], "-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") = Length([Field1]) = -1

Then "Pass"

Else "Fail"

Endif

//this only tests uppercase alphabets, 0-9 and hyphen

You can read about this function here:

https://help.alteryx.com/20213/designer/conversion-functions

 

Not as elegant as regex, but it was easier for me to read the code

Hope it helps anyone encountering the same problem

ラベル
トップのソリューション投稿者