A Simple Regex for Rails Email Validation

Here’s my quick-and-dirty Rails email regex:

/^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i

Declare the regex somewhere near the beginning of your User model, like so:

EMAIL_REGEX = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i

A lot of code is yet to be written. Onward!

[Check this regex out on Rubular. It’s the best Rails regex tool in history!]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s