Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devise validation of an email address returns: 'is invalid' #32

Closed
ChristofferJoergensen opened this issue Jun 3, 2014 · 12 comments
Closed

Comments

@ChristofferJoergensen
Copy link

Great gem that you have shared with us!

I am having some problems validating the email attribute in my User model. I am using devise's validatable module to perform validation of the uniqueness of the email as well as some regex validations I guess.

When using judge on my form, I get back this 'is invalid' error when I enter any email into my form.

Any idea why this is?

My initializer:

Judge.configure do
  expose User, :email
end

My js:

judge.validate document.getElementById("user_email"),
  valid: (element) ->
    console.log "Good job"
  invalid: (element, messages) ->
    console.log messages.join(', ')

My form:

= form_for(resource, :builder => Judge::FormBuilder, :as => resource_name, :url => registration_path(resource_name)) do |f|
  = f.text_field :email, :validate => true

My log:

Started GET "/judge?klass=user&attribute=email&value=my%40email.com&kind=uniqueness" for 127.0.0.1 at 2014-06-03 18:44:37 +0200
Processing by Judge::ValidationsController#build as JSON
  Parameters: {"klass"=>"user", "attribute"=>"email", "value"=>"my@email.com", "kind"=>"uniqueness"}
Completed 200 OK in 5ms (Views: 0.2ms)

And when I remove the validatable module from my User model, no errors are returned.

@Vadorequest
Copy link

Take a look to this: #25

it was because of the regex itself for me.

@ChristofferJoergensen
Copy link
Author

Thanks for your comment. But the problem for me is here that devise defines the email regex, and I would really like not to overwrite Devise validation functionality.

@Vadorequest
Copy link

This isue too could bring you more information about the issue, maybe your Device gem override the native regex way.

#19

@ricardodovalle
Copy link

@ChristofferJoergensen , same issue.
Did you solve?
Thanks

@ChristofferJoergensen
Copy link
Author

Hi @ricardodovalle. No, I have not yet solved it. I am a little bit afraid of implementing some custom regex override. I feel like I should stick to the validations that Devise has implemented.

@grammakov
Copy link

Having the exact same issue.

@tommyalvarez
Copy link

+1 same issue.

@codemilan
Copy link

+1 same issue for devise validatable, how can we fix.

@Gee-Bee
Copy link

Gee-Bee commented Apr 1, 2015

Same here. Judge mark any email as invalid.
Devise regex: /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
Judge generated regex: (?-mix:\\A[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+\\z)

@jamesmk
Copy link
Collaborator

jamesmk commented Apr 1, 2015

@ChristofferJoergensen There's nothing magical about Devise's validations, you can see them here:
https://github.com/plataformatec/devise/blob/18b6064d74726147eccd69b24812000074261bbb/lib/devise/models/validatable.rb#L29

If you don't want to remove the validatable module complete, Devise offers a config in their initializer to just override the email regex:

# 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.
# config.email_regexp = /\A[^@]+@[^@]+\z/

As you see from the comments (and source here: https://github.com/plataformatec/devise/blob/18b6064d74726147eccd69b24812000074261bbb/lib/devise.rb#L108) their regex is actually pretty weak.

@danieldocki
Copy link

+1 same here with devise

@jamesmk
Copy link
Collaborator

jamesmk commented May 25, 2015

fixed in #60

@jamesmk jamesmk closed this as completed May 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants