S
S
Sergey2017-08-19 21:25:22
go
Sergey, 2017-08-19 21:25:22

Help with regular Go?

Can you help with the function

/////Функция проверяет номер на валидность
func check_num(client int , id_dispach int)  {
  /*
  Могут поступить номера
       ‎+79095876084
        79095876084
        89095876084
   */
  fmt.Println("Проверяю номер на валидность . Номер который поступил в систему ",client)
  // проверяю формат номеров
  match_kz, _ := regexp.MatchString("^[+0-9]{1}{11,12}$", client)   ///регулярка  онлайк конструктор https://uiregex.com/ru
  match_rus, _ := regexp.MatchString("^[+0-9]{1}{11,12}$", client)   ///регулярка  онлайк конструктор https://uiregex.com/ru
  // как замена множественным if elseif
  switch {
  case match_kz:
    fmt.Println("Номер Казахстан",client,id_dispach)
  case match_rus:
    fmt.Println("Номер Россия",client,id_dispach)
  default: ///если не попал ни под одно условие уйду сюда
    fmt.Println("Номер не коректный",client,id_dispach)
    return err
  }
}

how do I after I checked the number for the fact that it fits the case convert the number to a single format
For example, in the dialplan, I did it like this through a regular expression
<extension name="out">
            <condition field="destination_number" expression="^(?:\+)?(?:[7,8])?72(\d{8})$">
                <action application="bridge" data="{leg_timeout=40,ignore_early_media=true}sofia/gateway/goip16/007872$1"/>
            </condition>
</extension>

That is, how can I make the number always be transmitted in the format
79095876084

Answer the question

In order to leave comments, you need to log in

2 answer(s)
4
4iloveg, 2017-08-19
@4iloveg

Does the specified service find this regular number?"^[+0-9]{1}{11,12}$"

A
Alexander Pavlyuk, 2017-08-21
@pav5000

First, you're using the wrong quotes.
This will not work because the backslash inside double quotes is used for escaping. It should be like this:
Secondly, here the regular expression is compiled for each check call, which is very slow, you need to compile it in advance and then use it. For example, like this .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question