Keats / validator

Simple validation for Rust structs
MIT License
1.98k stars 142 forks source link

Email length validation before regex #211

Closed pintariching closed 2 years ago

pintariching commented 2 years ago

I added validation for emails before doing regex validation on the input. However these RFC standards are a bit confusing and I'm unsure what lengths to set each part of the address to.

The regex, I think, validates the lengths like [??].[??]@[63].[63]

Is the length of the user part being validated?

Fixes #209

pintariching commented 2 years ago

Or should the length of each part be an argument that can be optionaly passed in when creating the validation like so: #[validate(email(user_part_length = 63, domain_part_length = 255))]

Glitchy-Tozier commented 2 years ago

Thank you for creating this PR!

Or should the length of each part be an argument that can be optionaly passed in when creating the validation like so: #[validate(email(user_part_length = 63, domain_part_length = 255))]

I don't think this is needed. If emails are tested accordingly to an accepted standart, there shouldn't be a need for detailed customizability. (and if there is no standard, #209 can't be implementd properly)

However these RFC standards are a bit confusing and I'm unsure what lengths to set each part of the address to.

I also find it confusing. Some of the posts I read (see original issue) suggest that the initial "320" was an error, and that it's actually "64 for username, 254 for full address (including the username!)

"So, when creating a new email address, limit your username to 64 or fewer characters, and the total number of characters to 254."

I haven't spent enough time reading official sites though, so I'm not sure which interpretation is correct.

Keats commented 2 years ago

+1 on not allowing customizing the values. I'll have to search a bit to know what are the correct values though.