How to make the last digit as optional in asterisk dialplan?

I want to allow only extensions 99 and 999. How to make the last digit as optional? How can I achieve this through dialplan?

It depends on what you want. You could use two patterns or a single and make the last digit optional. The docs are your friend.

You could also say that 998 maps to 99 or 14; it’s up to you. In case you are using FreePBX, what I wrote may not be valid. You might need to write some custom rules.

Are these different extension numbers for the same extension, or two different extensions? In the latter case, that is not at all a sensible numbering plan.

If they are synonyms, just repeat the dialplan for each, or have the one go to the other.

If they are distinct, you may need to use “_99!” for the first one, to avoid a timeout waiting for a possible final digit. (Disabling overlap dialling may be enough, but I’ve not used numbering plans with this sort of problem.)

Different extension numbers for same extension