4 ms·
This is the official regex to check for mail validity. \A(?:[a-z0-9!#$%&'+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'+/=?^_`{|}~-]+)* | "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x
by iogf 9y ago
This is the official regex to check for mail validity.
\A(?:[a-z0-9!#$%&'+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'+/=?^_`{|}~-]+)*
| "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
| \\[\x01-\x09\x0b\x0c\x0e-\x7f])")
@ (?:(?:[a-z0-9](?:[a-z0-9-][a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-][a-z0-9])?
| \[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:
(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
| \\[\x01-\x09\x0b\x0c\x0e-\x7f])+)
\])\z
according to http://www.regular-expressions.info/email.html http://www.regular-expressions.info/email.html
I honestly think that one would be more readable and comprehensive in crocs's syntax. It is not about being only readable it is about a way of reasoning to come up with your regex, crocs permit you to better reason than using regex's syntax. When one uses regex's syntax to reason it is sort of using a low level programming lang to reason, when things get complex it doesnt really pay off the shortness of regex's.
- nemetroid 9y agoIt would definitely be interesting to see it implemented in crocs! However, it's not really fair to suggest that regexes by necessity are monolithic and non-modular. You could construct that... thing... step by step. And likewise, writing the entire thing as a single crocs statement would be at least as unreadable. But my main point was that since crocs compiles down to regex, it doesn't let you do more than regex already does, and it inherits most of regexes' weaknesses. It does afford some level of type safety though, which could be argued makes up for the verbosity (and whether that verbosity is good or bad is probably a religious war).
- iogf 9y agoYes, there are interesting benefits about type safety consequently it improves debugging as well.
- iogf 9y agoThe main benefit about crocs it is purely epistemological in the sense it eases learning and consequently improves reasoning when implementing filters for content instead of using regex approach one would use crocs approach and get benefits from it permiting you to better reason. You can solve a lot of problems using euclidian geometry that you could solve using cartesian/analytic geometry it doesnt mean that you should use just one of them at all. The two permit you to abstract systems and predict behaviors.
- baudehlo 9y agoThat validates an RFC5322 email address which literally ONLY email clients need to do (and maybe a few things that process received email). Most things need to process and validate only RFC5321 (and 5890, 5891 and 5892 for Unicode) addresses.