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

Implement validation of email format #110

Closed
wants to merge 1 commit into from
Closed

Implement validation of email format #110

wants to merge 1 commit into from

Conversation

kad3nce
Copy link

@kad3nce kad3nce commented Jul 25, 2014

Uses a simple regex, which is far from perfect, but better than nothing.

Uses a simple regex, which is far from perfect, but better than nothing.
@hoxworth
Copy link
Contributor

The JSON Schema Draft 04 spec states "A string instance is valid against this attribute if it is a valid Internet email address as defined by RFC 5322, section 3.4.1". Unfortunately, this regex is not RFC 5322-compliant. In fact, generating a single regex for RFC 5322 email validation is not incredibly simple.

I definitely would like to flesh this validation out, but do not want to break implementations that might actually attempt to validate email addresses that this regex would reject, even when they are RFC-5322 compliant. Will leave open for future improvements.

@mpalmer
Copy link
Contributor

mpalmer commented Sep 18, 2014

I've got a ready-built regexp for e-mail that handles everything in RFC2822 (I don't know if 5322 changes anything) that can be handled via regexp (there's one never-used part of the valid syntax that is recursive) at https://github.com/mpalmer/email-address-validator/blob/master/lib/email_address_validator/regexp.rb. Feel free to yoink it across (with credit, preferably) rather than trying to build your own.

@iainbeeston
Copy link
Contributor

Another option is to bring in the Mail gem to parse the email address, and raise a validation error if it doesn't parse (email address parsing is really hard)

@mpalmer
Copy link
Contributor

mpalmer commented Sep 18, 2014

That would work reasonably well too, as long as the extra dependencies (mail, mime-types, and Ruby 1.9.2) aren't considered excessive. Normally I wouldn't consider that a problem, but given that json-schema is dependency-free now, it might be a deal-breaker here.

@pd
Copy link
Contributor

pd commented Oct 25, 2014

After #131 / #132 lands, I think json-schema should probably drop support for email and hostname outright, since they're currently both no-ops anyway. The spec says:

Implementations MAY support the "format" keyword. Should they choose to do so:
they SHOULD implement validation for attributes defined below;
they SHOULD offer an option to disable validation for this keyword.

And RFC2119, which defines MUST, MAY, SHOULD et al:

SHOULD This word, or the adjective "RECOMMENDED", mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

Given the complexity of validating an email in line with RFC5322, I'd say it's fair enough to say there are valid reasons to just punt on it. =)

@iainbeeston
Copy link
Contributor

Right. Maybe this could be added to the docs as an example as a custom validation=

@hoxworth
Copy link
Contributor

👍 on @iainbeeston 's suggestion on adding it to the docs on adding a custom validation format!

@hoxworth
Copy link
Contributor

Closing this out as a wontfix

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

Successfully merging this pull request may close these issues.

None yet

5 participants