Hacker News new | ask | show | jobs
by adalu 1524 days ago

  ```
  //pseudo Go
  import (
    "strings"
    "internal/inputs"
  )
  
  func emailValid(input inputs.ProfileInput) bool {
    if len(input.Email < 3) {
      return false
    }
    return strings.Contains(input.Email, "@")
  }
  ```
An email should be at least 3 chars long and contain a @ sign to be valid.

a@a can be a valid email address if your hostname is a and your mta accepts the email address. A user a may or may not exist (virtual).

And as the author wrote 10 years ago, if the mail doesn't arrive, no validation can help if the email address doesn't exist. But len>=3 and @ sign presence is enough of a sanity check.

1 comments

I like the simplicity, but @@@ isn’t a valid email address (and .@. isn’t too, same as @…---…, and soon enough we’ll quickly regress back to the original problem of having too long of a regex)