本文整理汇总了Golang中github.com/asaskevich/govalidator.IsEmail函数的典型用法代码示例。如果您正苦于以下问题:Golang IsEmail函数的具体用法?Golang IsEmail怎么用?Golang IsEmail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsEmail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WriteFeedback
// Establish connection to MongoDB and write feedback to collection
func WriteFeedback(name string, email string, text string) int {
// We like only correct e-mails
if !govalidator.IsEmail(email) {
fmt.Printf("'%v' is not an email!\n", email)
return NOT_AN_EMAIL
}
// Length of name can't be less than four letters and more than thirty two letters
if !govalidator.IsByteLength(name, 4, 32) {
fmt.Printf("Name '%v' has invalid length!\n", name)
return INVALID_NAME
}
// Length of text should be between 16 and 1024 letters
if !govalidator.IsByteLength(text, 16, 1024) {
fmt.Printf("Feedback '%v' has invalid length!\n", text)
return INVALID_NAME
}
url := os.Getenv("DATABASE")
fmt.Printf("DB_URL is %v\n", url)
sess, err := mgo.Dial(url)
if err != nil {
fmt.Printf("Can't connect to mongo, go error %v\n", err)
return DB_UNAVAILABLE
}
defer sess.Close()
sess.SetMode(mgo.Monotonic, true)
c := sess.DB("asaskevich").C("feedback")
err = c.Insert(&Feedback{name, email, text})
if err != nil {
fmt.Printf("Can't write to mongo, go error %v\n", err)
return CANT_WRITE_TO_DB
}
return OK
}
示例2: AddressIsValidFullFuzzy
func AddressIsValidFullFuzzy(address string, excludeExampleOrTest bool, excludeNumericTestAddress bool) bool {
address = strings.Trim(address, " ")
if len(address) < 6 { // [email protected]
return false
}
address = strings.ToLower(address)
valid, _, hostname := AddressIsValidFull(address)
if !valid {
return false
}
valid = govalidator.IsEmail(address)
if !valid {
return false
}
valid = HostnameIsValid(hostname)
if !valid {
return false
}
if excludeExampleOrTest {
test := DomainIsExampleOrTest(address)
if test {
return false
}
}
if excludeNumericTestAddress {
rsEmailFullNumeric := rxEmailFullNumeric.FindString(address)
if len(rsEmailFullNumeric) > 0 {
return false
}
}
return true
}
示例3: verifyFormat
func verifyFormat(val string, format string) error {
switch format {
case "date-time":
_, err := time.Parse(time.RFC3339, val)
return err
case "email":
if !govalidator.IsEmail(val) {
return fmt.Errorf("%q is not a valid email", val)
}
case "hostname":
if !hostnameRe.MatchString(val) || len(val) > 255 {
return fmt.Errorf("%q is not a valid hostname", val)
}
case "ipv4":
if !govalidator.IsIPv4(val) {
return fmt.Errorf("%q is not a valid IPv4 address", val)
}
case "ipv6":
if !govalidator.IsIPv6(val) {
return fmt.Errorf("%q is not a valid IPv6 address", val)
}
case "uri":
u, err := url.Parse(val)
if err != nil {
return err
}
// XXX: \noideadog{this makes all the tests pass, not sure how it really should be validated}
if u.Host == "" {
return fmt.Errorf("%q is not absolute", val)
}
}
return nil
}
示例4: EditEmail
//edit email
func EditEmail(c web.C, w http.ResponseWriter, r *http.Request) {
var userId int
if CheckToken(r.FormValue("token"), w) == false {
return
}
//Get user_id by token render json error if crash ?
if userId = GetUserIdWithToken(r.FormValue("token"), w); userId == -1 {
return
}
var email = r.FormValue("email")
//delete all space in var email
email = strings.Replace(email, " ", "", -1)
//check if email's syntax is correct
if govalidator.IsEmail(email) == false {
RenderJSON(w, RenderStructError("email", "your email haven't a good syntax"), http.StatusBadRequest)
return
}
//check if email is already used
if IsEmailExist(email) == true {
RenderJSON(w, RenderStructError("email", "email is already used"), http.StatusBadRequest)
return
}
//query update email
_, err := gest.Db.Exec("UPDATE account SET email=$1 WHERE id=$2", email, userId)
LogFatalError(err)
RenderJSON(w, RenderStructOk(), http.StatusOK)
}
示例5: Validate
// Validate ...
// TODO: unify somehow, to have centralized place where email (or any other field) is validated
func (prr *PasswordRecoveryRequest) Validate(builder *lib.ValidationErrorBuilder) {
if !validator.IsByteLength(prr.Email, 6, 45) {
builder.Add("email", "validation_error.email_min_max_wrong")
} else if !validator.IsEmail(prr.Email) {
builder.Add("email", "Invalid email address.")
}
}
示例6: EmailValidator
//EmailValidator for validation of email inputs
func EmailValidator(Error string) ItemValidator {
return NewValidator(func(field *FormItem) bool {
if !govalidator.IsEmail(field.Value) {
return false
}
return true
}, Error)
}
示例7: ValidateFormatOfEmail
func ValidateFormatOfEmail(resource Resource, attribute string) {
value := reflect.ValueOf(resource).Elem()
value = reflect.Indirect(value).FieldByName(attribute)
if govalidator.IsEmail(value.String()) == false {
resource.Errors().Add(attribute, "is not email")
}
}
示例8: Decode
func (n *NewEmail) Decode() error {
n.Email = strings.Trim(strings.ToLower(n.Email), " ")
if n.Email == "" || !govalidator.IsEmail(n.Email) {
return Errors{
"email": "Valid email is required",
}
}
return nil
}
示例9: validateChartMaintainer
func validateChartMaintainer(cf *chart.Metadata) (lintError support.LintError) {
for _, maintainer := range cf.Maintainers {
if maintainer.Name == "" {
lintError = fmt.Errorf("Chart.yaml: maintainer requires a name")
} else if maintainer.Email != "" && !govalidator.IsEmail(maintainer.Email) {
lintError = fmt.Errorf("Chart.yaml: maintainer invalid email")
}
}
return
}
示例10: validateChartMaintainer
func validateChartMaintainer(cf *chart.Metadata) error {
for _, maintainer := range cf.Maintainers {
if maintainer.Name == "" {
return errors.New("each maintainer requires a name")
} else if maintainer.Email != "" && !govalidator.IsEmail(maintainer.Email) {
return fmt.Errorf("invalid email '%s' for maintainer '%s'", maintainer.Email, maintainer.Name)
}
}
return nil
}
示例11: NewUserFunc
// NewUserFunc creates the default parser of login HTTP request
func NewUserFunc(idName string) UserFunc {
return func(r *http.Request, us store.Store) (ou OAuth2User, err error) {
var c store.Conds
id := r.Form.Get(idName)
if id == "" {
serr := store.Error(http.StatusBadRequest, "empty user identifier")
err = serr
return
}
// different condition based on the user_id field format
if govalidator.IsEmail(id) {
c = store.NewConds().Add("email", id)
} else {
c = store.NewConds().Add("username", id)
}
// get user from database
u := us.AllocEntity()
err = us.One(c, u)
if err != nil {
serr := store.ExpandError(err)
if serr.Status != http.StatusNotFound {
serr.TellServer("Error searching user %#v: %s", id, serr.ServerMsg)
return
}
err = serr
return
}
// if user does not exists
if u == nil {
serr := store.Error(http.StatusBadRequest, "Username or Password incorrect")
serr.TellServer("Unknown user %#v attempt to login", id)
err = serr
return
}
// cast the user as OAuth2User
// and do password check
ou, ok := u.(OAuth2User)
if !ok {
serr := store.Error(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
serr.TellServer("User cannot be cast as OAuth2User")
err = serr
return
}
return
}
}
示例12: Valid
// Valid validates email. If the email is temporary it returns false and an error explaining
// why it is not valid. For valid email it returns true, and the error is nil.
func Valid(email string) (bool, error) {
if !govalidator.IsEmail(email) {
return false, errors.New("Bad email address")
}
sep := strings.Split(email, "@")
_, err := checkDisposable(sep[1])
if err != nil {
return true, nil
}
return false, errors.New("This is a temporary email")
}
示例13: validateContact
func (m *Order) validateContact() error {
if m.Contact == "" {
return nil
}
if govalidator.IsEmail(m.Contact) != true {
return errors.InvalidType("contact", "body", "email", m.Contact)
}
return nil
}
示例14: validateEmail
func (m *User) validateEmail() error {
if m.Email == "" {
return nil
}
if govalidator.IsEmail(m.Email) != true {
return errors.InvalidType("email", "body", "email", m.Email)
}
return nil
}
示例15: checkEmails
func checkEmails(emails []string) (errs []error) {
for _, addr := range emails {
if len(addr) == 0 {
return
}
if ok := valid.IsEmail(addr); !ok {
errs = append(errs, fmt.Errorf("Invalid email address. email: %s", addr))
}
}
return
}