Go 輸入檢查

func (s *validate) isEmail() *validate {
    if s.r == true {
        re := regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
        var match = re.MatchString(s.i)
        if !match {
            s.r = false
            s.e = "invalid email"
        }
    }
    return s
}

func (s *validate) oneNumber() *validate {
    if s.r == true {
        re := regexp.MustCompile("[0-9]+")
        var match = re.MatchString(s.i)
        if !match {
            s.r = false
            s.e = "does not contain atleast one numeric character"
        }
    }
    return s
}

特殊符號檢查

func (s *validate) isSpecialCharacter() *validate {
    if s.r == true {
        re := regexp.MustCompile("\\`|\\~|\\!|\\@|\\#|\\$|\\%|\\^|\\&|\\*|\\(|\\)|\\+|\\=|\\[|\\{|\\]|\\}|\\||\\|\\'|\\<|\\,|\\.|\\>|\\?|\\/|\"|\\;|\\:|\\s")
        var match = re.MatchString(s.i)
        if !match {
            s.r = false
            s.e = "does not contain atleast one special character"
        }
    }
    return s
}