[Answered ]-RegexValidator in Django Models not validating email correctly

1👍

The [nith.ac.in] does not parse literal text, it parses any character in te group, meaning it can end with a sequence of ns, is, nis, etc.

Your regex should look like:

email = models.EmailField(
    unique=True,
    validators=[
        RegexValidator(
            regex=r'^[2][2][a-zA-Z]{3}\d{3}@nith[.]ac[.]in$',
            message='Only freshers with college email addresses are authorised.',
        )
    ],
)

Leave a comment