Validate an email address : Utility Regexps « Development « Ruby






Validate an email address


def probably_valid?(email)
 valid = '[A-Za-z\d.+-]+' # Commonly encountered email address characters
 (email =~ /#{valid}@#{valid}\.#{valid}/) == 0
end

#These give the correct result.
probably_valid? 'joe@example.com'                # => true
probably_valid? 'joe@examplecom'                 # => false

 








Related examples in the same category

1.Validate an email address with Resolv::DNS
2.Checking a Credit Card Checksum