Closed rajivkr closed 11 months ago
IMO the email should be validated according to RFC 2822, which should allow using the "+" in the local part
I can't reproduce your behavior. Plus sign in email passes validation. This was discussed in the underlying validation framework validatorjs 8 years ago
Here's my snippet, I get Validation success
:
import { validate, IsEmail } from "class-validator";
class User {
@IsEmail()
email: string;
}
let user = new User();
post.user = "stephen+spam@gmail.com";
validate(user).then((errors) => {
if (errors.length > 0) {
console.log("Validation failed. errors: ", errors);
} else {
console.log("Validation success");
}
});
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Recently learnt that gmail has an option to test as multiple id's by adding '+1', '+2', i.e, if you have
hello@gmail.com
, you can usehello+1@gmail.com, hello+2@gmail.com
etc. to get emails to samehello@gmail.com
inbox.The problem: However, with this logic, i see that
@IsEmail()
is throwing an error for emails with '+' sign, is there a way i can get around this? Currently using this regex instead, but can this be done usingisEmail()
itself?