Validator: validate fqdn fails if the domain name starts with integer number

Created on 24 Apr 2020  路  3Comments  路  Source: go-playground/validator

Package version eg. v8, v9:

v9

Issue, Question or Enhancement:

If a fqdn starts with an integer f.e. "0.de.pool.ntp.org", the validation fails. The example "0.de.pool.ntp.org" is a valid ntp-server (see https://www.pool.ntp.org/zone/de).

Code sample, to showcase or reproduce:

package main

import(
    "fmt"
    "gopkg.in/go-playground/validator.v9"
)

type SettingsNtp struct {
    NtpServer string `json:"ntpServer" validate:"required,ipv4|fqdn"`
}

func main() {
    validNtp1 := SettingsNtp{ NtpServer: "de.pool.ntp.org"} // valid ntp-server see https://www.pool.ntp.org/zone/de
    validNtp2 := SettingsNtp{ NtpServer: "0.de.pool.ntp.org"} // valid ntp-server see https://www.pool.ntp.org/zone/de

    fmt.Println("validator fqdn")

    validate := validator.New()
    errs := validate.Struct(validNtp1) //this validation is succeeded
    if errs != nil {
        fmt.Println(errs)
    } else {
        fmt.Println("No errors validNtp1")
    }

    errs = validate.Struct(validNtp2) //this validation fails
    if errs != nil {
        fmt.Println(errs)
    } else {
        fmt.Println("No errors validNtp2")
    }
}

bug good first issue help wanted v10

All 3 comments

@deschmih thanks for reporting.

Hoping someone can help with this as my time is very limited ATM.

This issue was resolved, it should be closed

Many thx

Was this page helpful?
0 / 5 - 0 ratings