0

i want to validate email but i couldn't. is there method to validate? param[0] is email. if param[0] =~ Devise.email_regexp is not work.

if param[0] =~ Devise.email_regexp
  {email: param[0], reason: I18n.t("user.error.invalid_email")}
Michael O'Neill
  • 946
  • 7
  • 22
  • 2
    Check out this SO question: https://stackoverflow.com/questions/22993545/ruby-email-validation-with-regex – Marcus Christiansen Mar 16 '18 at 15:18
  • You know that `devise`s built in email validation is extraordinarily simple. e.g. `/\A[^@\s]+@[^@\s]+\z/` *"Email regex used to validate email formats. It simply asserts that one (and only one) @ exists in the given string. This is mainly to give user feedback and not to assert the e-mail validity."* straight from the config file – engineersmnky Mar 16 '18 at 16:12
  • 1
    @engineersmnky what’s wrong with spaces? They are perfectly allowed in RFC. https://stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression – Aleksei Matiushkin Mar 16 '18 at 16:15
  • shouldn't you use `unless`? because if the condition in the if is `true`, `param[0]` is email. And you are returning an error in this case. – Ana María Martínez Gómez Mar 17 '18 at 22:44

0 Answers0