Search code examples
regexasterisk

Asterisk Dialplan Phone exten to RegEx


Need to build a RegEx, that came from asterisk dialplan (Brazil Number)

valid      = 0021987126408
not valid  = 002198712640
not valid  = 3021987126408
valid      = 0021987126408

need to validate asterisk with dialplan => 00ZX[789]XXXXXXXXX

check in order .....

  • check if the two first numbers is ZERO

  • check ZX (brazilian DD)

  • check (7,8 or 9)

  • check if XXXXXXXXX has the same quantity of numbers in the end

basicly transcribe asterisk Dialplan to Normal REGEX.


Solution

  • RegEx = ^(00\d{2}[7-9]\d{8})$

    valid      = 0021987126408
    not valid  = 002198712640
    not valid  = 3021987126408
    valid      = 0021987126408