Expression to validate that part of a string is numeric

Hi all,

I’m trying to write an expression for a validate rule that confirms that only a portion of a determined string is numeric.

Eg. the string is an externally provided ID that includes a prefix then a series of numbers. I need to validate that the series of numbers is, in fact, a series of numbers.

Example string is something like “ABCD-123456”. All IDs follow this format, though the length of both the prefix and the number string can vary.

The intuitive solution to me was to try @isNumber(@String.whatComesAfterFirst(.ID, ’-’)) but any syntax configuration of this expression that I try is failing

Am I making a glaring mistake in my expression logic? Or is there a better way to achieve this check?

Hello @SamT17287272

The expression you mentioned looks good. Few things to verify on what you are getting in the “.ID“ property.

  1. Ensure that you are not getting any spaces or special or unicode or hidden characters before / in between / after the number in .ID property. To cater that situation, you can use trim function like this @isNumber(@String.trim(@String.whatComesAfterFirst(@String.trim(.ID), ‘-’)))
  2. Ensure you have the Null / empty handling
  3. If you want an alternative, you can use regular expression for your requirement like this @String.pxContainsViaRegex(@String.trim(.ID), “^[A-Z]±\\d+$“, true)

Hope this helps

Regards

JC

1 Like