Last active
June 7, 2023 08:54
-
-
Save ngelx/3bcce7c1ebe16d58149e79b94c6159f3 to your computer and use it in GitHub Desktop.
Regexp to validate emails in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Strictly adhere to email address standards and disallow hyphens at the beginning or end of the domain name. | |
# Use https://rubular.com for live testing. | |
def validate_email(string) | |
(string.downcase =~ /\A[a-zA-Z0-9._%+-]+@[a-zA-Z0-9](?:[a-zA-Z0-9\-_]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9]*)(?:\.[a-zA-Z]{2,})+\z/)&.zero? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment