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
Conversation
Uses a simple regex, which is far from perfect, but better than nothing.
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. |
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. |
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) |
That would work reasonably well too, as long as the extra dependencies ( |
After #131 / #132 lands, I think json-schema should probably drop support for
And RFC2119, which defines MUST, MAY, SHOULD et al:
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. =) |
Right. Maybe this could be added to the docs as an example as a custom validation= |
👍 on @iainbeeston 's suggestion on adding it to the docs on adding a custom validation format! |
Closing this out as a wontfix |
Uses a simple regex, which is far from perfect, but better than nothing.