Asterisk Rexex Help

I am trying to validate a user input using regex and I am not hitting the mark. I admit I am out of my element here.

I would like to make sure the user input is ether the digits 0 or 1 or is a 10 digit input that meets the [2-9]XXXXXXXXX criteria.

I have tried:

There is an additional requirement, though not as urgent, to skip the defined enter digit timeout if the user enters the 0 or 1 since there would be no need to wait for more digits.

Can anyone guide me a little bit here? Thanks in advance!

Some progress


appears to work for my urgent need, but I am still trying to figure out how to make pressing 0 or 1 instantly advance instead of waiting for the time out.

One typically uses dialplan patterns, not general regular expressions, for this.

To force an early match, use ! to terminate the dialplan pattern.

1 Like

As much as I would like to say its not, this is my first regex rodeo. Can you give me an example of it in use (ideally in my use case :slight_smile: ) to help cement my understanding.

If they push 1 or 0 it forces an early match, otherwise it has to be a 10-digit number starting between 2 and 9.

Would it be like this?

Thanks again for the guidance!

Sounds more like a dial plan (digit map) in a phone or ATA.

Its actually in FreePBX Dynamic Routes module PBX GUI : Dynamic Routes User Guide (

Specifically, the Validation component of the module:
Validation rule using an Asterisk regular expression (see Asterisk REGEX). For example to ensure the caller DTMF input is between 3 and 4 digits long you could use ^[0-9]\{3,4\}$ Note that the curly braces and other Asterisk special character need to be escaped.

“FreePBX is not Asterisk, they have their own support forum…”

Yes, I know, but am having no luck there and since this question is more broadly about Asterisk REGEX, I think the question still fits here. Just looking for one last little push to get me over the finish line if anyone has any expertise with Asterisk REGEX.

exten => _0!,1,....
exten => _1!,1,.....
exten => _NXXXXXXXXX,1,....

As I said it is Asterisk extension patterns that caters for skipping timeouts. not regular expressions. Actually, you don’t need to use patterns and ! in this case, as as there is no conflict between 0 and 1 and the pattern.

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