Matching field to a single digit number

I have a field which contains strings like "0","1"..."10","11"..."23".
How do I get an if statement where I take only fields which match single digits? ie. "0","1"...."9"?

Currently what I have is this:

if [tmHour] =~ /[0-9]{1}/ {
    *code here*
}

But it still matches everything.

You would need to anchor it, otherwise it will match the first digit of a multi-digit string.

if [tmHour] =~ /^[0-9]$/
1 Like

Thank you @Badger!
Your solution works just fine.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.