Advertisement
|
This simple code validates an email address to ensure that it complies with standard formatting.
You can put this in your model like so:
class Person < ActiveRecord::Base
validates_format_of :email, :with => /^\S+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/ix
end
If you have PHP code - try this..
$valid_email = preg_match('/^\S+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/', $email);
Read: Rails validates_format_of :email - Email Address Regular Expression - And PHP too