BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
robust1972
Community Trekker

how to use jsl to test if a string contains only A~Z and 0~9?

how to use jsl to test if a string contains only A~Z and 0~9?

my data shall  contains only A~Z and 0~9 but when 1 or few bit flip then there is not printable characters.

many thanks in advance!

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: how to use jsl to test if a string contains only A~Z and 0~9?

You can use regular expressions to check this.  Create a new column that contains the following formula:

If (Regex(:Name("2nd"), "^[a-zA-Z0-9]+$") == :Name("2nd"), "Yes", "No")


The new column will have the value "Yes" if it is purely alphanumeric, "No" otherwise.

0 Kudos
3 REPLIES 3
pmroz
Super User

Re: how to use jsl to test if a string contains only A~Z and 0~9?

You can use regular expressions to check this.  Create a new column that contains the following formula:

If (Regex(:Name("2nd"), "^[a-zA-Z0-9]+$") == :Name("2nd"), "Yes", "No")


The new column will have the value "Yes" if it is purely alphanumeric, "No" otherwise.

0 Kudos
robust1972
Community Trekker

Re: how to use jsl to test if a string contains only A~Z and 0~9?

thanks for your reply, PMroz.

What ^ and +$ for?

how can I make it return 1 or 0 so that I could use it together with other comparison algorithm?

0 Kudos
pmroz
Super User

Re: how to use jsl to test if a string contains only A~Z and 0~9?

The ^ means the start of the string, the + means to match at least one character, and the $ means the end of the string.

To return a 1 or 0 simply change Yes to 1 and No to 0:

If (Regex(:Name("2nd"), "^[a-zA-Z0-9]+$") == :Name("2nd"), 1, 0)

There are a ton of websites out there that explain regular expressions btw.

0 Kudos