dev env
This commit is contained in:
parent
6185a59de9
commit
9e16843a29
8 changed files with 178 additions and 123 deletions
|
|
@ -1,57 +0,0 @@
|
|||
package orders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isValidPolishMobile(nineDigitNum string) bool {
|
||||
if len(nineDigitNum) != 9 {
|
||||
return false
|
||||
}
|
||||
|
||||
firstDigit := nineDigitNum[0]
|
||||
|
||||
if firstDigit < '4' || firstDigit > '8' {
|
||||
return false
|
||||
}
|
||||
|
||||
prefix2 := nineDigitNum[:2]
|
||||
validPrefixes := map[string]bool{
|
||||
"45": true,
|
||||
"50": true, "51": true, "53": true, "57": true,
|
||||
"60": true, "66": true, "69": true,
|
||||
"72": true, "73": true, "78": true, "79": true,
|
||||
"88": true,
|
||||
}
|
||||
|
||||
return validPrefixes[prefix2]
|
||||
}
|
||||
|
||||
func parsePhone(input string) (string, error) {
|
||||
input = strings.TrimSpace(input)
|
||||
|
||||
if strings.HasPrefix(input, "+48") {
|
||||
input = strings.TrimPrefix(input, "+48")
|
||||
} else if strings.HasPrefix(input, "0048") {
|
||||
input = strings.TrimPrefix(input, "0048")
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`\D`)
|
||||
cleaned := re.ReplaceAllString(input, "")
|
||||
|
||||
if len(cleaned) == 11 && strings.HasPrefix(cleaned, "48") {
|
||||
cleaned = cleaned[2:]
|
||||
}
|
||||
|
||||
if len(cleaned) != 9 {
|
||||
return "", fmt.Errorf("Numer telefonu musi mieć 9 cyfr")
|
||||
}
|
||||
|
||||
if !isValidPolishMobile(cleaned) {
|
||||
return "", fmt.Errorf("Nieprawidłowy numer telefonu — podaj polski numer komórkowy")
|
||||
}
|
||||
|
||||
return cleaned, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue