Search code examples
regexvalidationcastle-activerecordcastle

What specific Regex does Castle Validator ValidateEmail use?


I have two interacting systems in one we are using Castle Validator for our validation, the other is coded by hand, I need to ensure the email validation between these two systems is a match; the problem is I have not been able to find documentation of the Regex that castle uses for email.

There is this question but the links provided are all dead.


Solution

  • After looking through the repo history I was able to find the regex (separated into multiple lines for readability):

    ^([a-zA-z0-9_\-\.\'\+]+)
    @((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))
    ([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
    

    A side note: this regex is still pretty broken with how the @[ipaddress] is allowed.

    For example this: [email protected]] is registered as valid as would this: johndoe@[111.111.111.com