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("invalid length: expected 9 digits, got %d", len(cleaned)) } if !isValidPolishMobile(cleaned) { return "", fmt.Errorf("invalid mobile prefix: %s does not match Polish mobile allocations", cleaned[:2]) } return cleaned, nil }