Rails: validating email in a model

I am importing an excel sheet containing (name, date of birth, email) and validating the email in the model with below code.

validates_format_of :email, :with => /^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/, :message => "Invalid email ID"

      

Now I have to show people with the wrong email format. Can I check this or in any other way ...

Thank you in advance

+3


source to share


3 answers


With this, I got the name of the person whose email address is invalid



  if @person.save

 else
    @err << {:name => ..............,:error => @person.errors.messages}
 end

      

+2


source


Go to http://my.rails-royce.org/2010/07/21/email-validation-in-ruby-on-rails-without-regexp/ This will really help you.



+3


source


I would humbly recommend against trying to validate email formats due to the large number of combinations and formats that make up a valid email address.

If you want to continue this path, then the full RegEx can be seen here .

NTN

+1


source







All Articles