Check if variable is a phone number including + sign

Hi,

I want to check if a variable (userpart in PAID or From header) is a phone number. userpart can come in both +123421432542 and 123123124124 formats.

I have a regex ^+?\d+$ that works for this validation, but I can not get it to work in asterisk 16.2.1:

same => n,Set(CALLEE="+123456778")
same => n,Set(REG1="^\+?\d\+$")
same => n,Set(ISPHONE=${REGEX("${REG1}" ${CALLE})})
same => n,gotoif($[${ISPHONE}]?nonanon)

I tried different ways of escaping plus and dollar and backslash signs but without success.

I think you can’t use the last plus sign.
Have you tried alternatives like that?

same => n,Set(REG1="^+?\d{8,15}")

Thanks a lot for the suggestion. It is even better as it allows to detect unreasonably short or long numbers! I had to escape plus sign thought.

Unfortunately it does not work as expected. It does not detect an “unavailable” string as not being a valid phone number:

Executing [s@noanonymous:1] Set("PJSIP/trunk-00001a95", "PAID=<sip:unavailable@unknown.invalid>") in new stack
    -- Executing [s@noanonymous:2] Set("PJSIP/trunk-00001a95", "CALLEE=<sip:unavailable") in new stack
    -- Executing [s@noanonymous:3] Set("PJSIP/trunk-00001a95", "CALLEE=unavailable") in new stack
    -- Executing [s@noanonymous:4] Set("PJSIP/trunk-00001a95", "REG1="^\+?\d{8,25}"") in new stack
    -- Executing [s@noanonymous:5] Set("PJSIP/trunk-00001a95", "ISPHONE=1") in new stack
    -- Executing [s@noanonymous:6] GotoIf("PJSIP/trunk-00001a95", "1?nonanon") in new stack

exten => s,1,Set(PAID=${PJSIP_HEADER(read,P-Asserted-Identity)})
same => n,Set(CALLEE=${CUT(PAID,@,1)})
same => n,Set(CALLEE=${CUT(CALLEE,:,2)})
same => n,Set(REG1="^\+?\d{8,25}")
same => n,Set(ISPHONE=${REGEX("${REG1}" ${CALLE})})
same => n,gotoif($[${ISPHONE}]?nonanon)

Could anyone familiar with asterisk regex internals shed light on the proper escaping methods, or other relevant information to get the validation working?