Dialplan function isNumeric()?

I’m looking for a way to determine if a variable is numeric. like:

or whatever the syntax.
Is something like $[“0123456789” > 0] a reliable way?

I would use regular expressions.

All builtin in functions are in upper case only.

Your last case won’t work as ’ and 0 always have the same relation.

So like this? :

exten => s,n,Set(IsNumeric=${REGEX("[0-9]" ${MYEXTENSION})}) exten => s,n,GotoIf($["${IsNumeric}" = "0"]?usecallerid)

Sorry, i cant test until later (production box)

That expression will match any string with at least one digit. You need to anchor, or use a pattern that matches non-digits. You can also test the restult of the regular expression directly, and for zero/nonj-zero tests, you don’t have to do an explicit comparison.

exten => s,n,GotoIf($[${MYEXTENSION} >= 0]?dialnumber) should work.

Another one is,
exten => s,n,GotoIf($[$["${MYEXTENSION}" = “${FILTER(0-9,${MYEXTENSION})}”] & $["${MYEXTENSION}" != “”]]?dialnumber)

–Satish Barot

Thanks guys for the input

exten => s,n,Set(IsNumeric=${REGEX("[0-9]" ${MYEXTENSION})}) exten => s,n,GotoIf($["${IsNumeric}" = "0"]?usecallerid)

worked perfectly. In my case the ${MYEXTENSION} was either going to be a named extension (channel) like “SIP/johnsphone-000ef” or an numeric extension (channel) like “SIP/100-000ef”, I just wanted a reliable way to determine the difference. (once i has stripped all the SIP/ etc away)

Shot Satish for the FILTER() hint, will remember that for next time.

same => n,GotoIf($["${REGEX("^[0-9]+$" ${CALLERID(num)})}" = “1”]?useID)