judgegem/judge

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

Closed this issue · 12 comments

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.

Take a look to this: #25

it was because of the regex itself for me.

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.

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

#19

@ChristofferJoergensen , same issue.
Did you solve?
Thanks

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.

Having the exact same issue.

+1 same issue.

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

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

@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.

+1 same here with devise

fixed in #60