本文整理汇总了Golang中github.com/asaskevich/govalidator.IsEmail函数的典型用法代码示例。如果您正苦于以下问题:Golang IsEmail函数的具体用法?Golang IsEmail怎么用?Golang IsEmail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsEmail函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:valm0unt,项目名称:gosite,代码行数:35,代码来源:feedback.go
示例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
}
开发者ID:VukDukic,项目名称:gotilla,代码行数:32,代码来源:mailutil.go
示例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
}
开发者ID:jmptrader,项目名称:validate-json,代码行数:33,代码来源:format.go
示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:35,代码来源:account_manage.go
示例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.")
}
}
开发者ID:escribano,项目名称:charon,代码行数:9,代码来源:password_recovery.go
示例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)
}
开发者ID:hypertornado,项目名称:prago,代码行数:9,代码来源:form.go
示例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")
}
}
开发者ID:tksasha,项目名称:go-balance-backend,代码行数:9,代码来源:format_of_email.go
示例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
}
开发者ID:thesoftwarefactoryuk,项目名称:podbaby,代码行数:9,代码来源:decoders.go
示例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
}
开发者ID:gabrtv,项目名称:helm,代码行数:10,代码来源:chartfile.go
示例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
}
开发者ID:runseb,项目名称:helm,代码行数:10,代码来源:chartfile.go
示例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
}
}
开发者ID:gourd,项目名称:kit,代码行数:56,代码来源:manager_defaults.go
示例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")
}
开发者ID:gernest,项目名称:mailchecker-go,代码行数:13,代码来源:mailchecker.go
示例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
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:11,代码来源:order.go
示例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
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:11,代码来源:user.go
示例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
}
开发者ID:Rompei,项目名称:vuls,代码行数:11,代码来源:config.go
示例16: Add_new_user
func (Lst_users *All_users) Add_new_user(new_user *User, Db *sql.DB, Pass []byte) (bool, error) {
if len(new_user.Mail) > 0 {
if valid.IsEmail(new_user.Mail) != true {
return false, nil
}
}
err := Db.QueryRow("SELECT setsuserdata2($1, $2, $3, $4, $5, $6, $7, $8);", 1, "user_particulier", new_user.Coord.Lat, new_user.Coord.Lon, new_user.Stats.CreationDate, new_user.Log, new_user.Mail, Pass).Scan(&new_user.Id)
if err != nil {
Lst_users.Logger.Println("Add_new_user: ", err)
return false, err
}
return true, nil
}
开发者ID:42MrPiou42,项目名称:Wibo_OpenProject,代码行数:13,代码来源:users.go
示例17: Validate
func (u *User) Validate() map[string]string {
var errs = make(map[string]string)
switch {
case u.Mail == nil:
errs["mail"] = "is required"
case u.Mail != nil && !govalidator.IsEmail(*u.Mail):
errs["mail"] = "is not valid"
case u.Password == nil:
errs["password"] = "is required"
}
return errs
}
开发者ID:quorumsco,项目名称:users,代码行数:14,代码来源:user.go
示例18: registerHandler
//for now just return submited params
func registerHandler(c *gin.Context) {
username := c.PostForm("username")
email := c.PostForm("email")
//we are using external library to validate email and other things if needed
if govalidator.IsEmail(email) {
//c.String(200, "Username is: %s and e-mail %s", username, email)
//or we can return JSON as well
c.JSON(200, gin.H{"username": username, "email": email})
} else {
//email is not valid we can't register this user
c.String(400, "We are sorry but email: %s is not valid e-mail adress", email)
}
}
开发者ID:ascepanovic,项目名称:GOQUIZ,代码行数:15,代码来源:main.go
示例19: Validate
func (user *User) Validate(repo UserRepository) error {
if user.Email == "" {
return errors.New("Cannot create User without email.")
}
if !govalidator.IsEmail(user.Email) {
return UserInvalidEmail
}
u, _ := repo.FindByEmail(user.Email)
if u != nil {
return UserDuplicateEmail
}
return nil
}
开发者ID:englandr,项目名称:recleague,代码行数:16,代码来源:validate.go
示例20: Validate
// Validate returns an error if a User struct does not satisfy the following
// conditions:
// * Username is 3 or more characters
// * Username is composed solely of alphanumeric characters
// * Email is a valid email address
// * Password is 8 or more characters
func (u User) Validate() (err error) {
if !valid.IsEmail(u.Email) {
err = errors.New(fmt.Sprintf("'%s' is not a valid email address", u.Email))
}
if len(u.Username) < 3 {
err = errors.New(fmt.Sprintf("'%s' is less than 3 characters", u.Username))
}
if len(u.Password) < 8 {
err = errors.New("Password must be at least 8 characters long")
}
if !valid.IsAlphanumeric(u.Username) {
err = errors.New(fmt.Sprintf("'%s' is less than 3 characters", u.Username))
}
return err
}
开发者ID:warreq,项目名称:gohstd,代码行数:22,代码来源:user.go
注:本文中的github.com/asaskevich/govalidator.IsEmail函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论