How to validate an email address using regular expressions

Anyone who writes web applications has likely built forms for users to enter their e-mail address. It’s considered a part of our basic identity now – like our name and address. It’s expected we have them.

But then, inevitably, once we’ve collected e-mails from all our customers and we go to use them – we get bounces. Which leaves us to clean up the mess – and there usually is a mess to clean up if we can’t tell the customer their order is ready or that we need information from them. Worse yet, we might just assume the information got through correctly and go on our merry way – leaving our customer dangling.

And while we’re quietly cursing our chubby-fingered (yet all important) customers, we wonder (or scream!) to ourselves why we don’t just write some code to validate the e-mail addresses when they’re entered?

But anyone who’s really looked into doing this will tell you that it gets deep quickly. What seems like it should be straightforward ends up arcane and impossible.

To begin with, e-mail address formats are covered by RFC 822 – which is filled with impenetrable discussions on “sequences of lexical symbols” such as “atoms”, “special characters”, “domain-literals” and “comments”.

“comments”? Yes, e-mail addresses can contain comments. I tested them too – and they work. A comment is (to the best of my knowledge) any text placed in parentheses anywhere in the email address. For example, my e-mail can be:

*, or
* kev(you da man!), or
* kevin@k(evin)

All these work – I tried them. Try validating that. I dare you.

Another bit of a twist is that you can also specify an IP address instead of a domain name. For example, I’m not only “”, I’m also kevin@

To make matters worse – as it should be expected to get – many mail servers won’t accept emails even if they are valid. For example, my mail server won’t accept kevin@ – the anti-spam controls bounce it.

Imagine – all that work to validate it, and it still won’t work. Makes you want to spend your days surfing these pages…

I even ran across one brave soul that came up with a regular expression that he was sure could validate an e-mail address. Here it is:

function isValidEmail(emailAddress) {
var re =
return re.test(emailAddress);

Wow. That’s a mouthful. Of course, I’m so jaded by now that I’m sure he must’ve missed something. Or that the emails will just get bounced anyway.

So is validating an email address impossible? Here’s the answer: It’s easy!

You don’t have to be a genius to validate email addresses. All you have to do is send a test e-mail to the customer! Really – this is the only way. If it gets through, the address is valid. If it bounces, then it’s not.

Now let’s just hope no one ever changes their email address once we validate it…

Are my points “valid”?

[Note: This is a repost of a post I originally wrote for The O'Reilly Network in December of 2002]

Posted in programming, ruby on rails | Tagged , , , | Leave a comment

‘seed’ data versus ‘testing’ data (and custom rake tasks) for Ruby on Rails

I’ve been a part of discussions on how to define ‘seed’ data versus ‘testing’ data on a Ruby on Rails project. Here’s a summary of what I’ve seen work well — please comment if you have anything to add.

Data loading is done for 2 purposes: First, to load data that will seed the system for ongoing use and that will live in the production environment, and second, to use for system testing. These two types of data are stored in two different ways.

Loading ‘seed’ data that will be required in production.

This data should be defined in /db/seeds.rb and loaded using the rake db:seed command. It should be loaded one time after initial database creation. If changes to the seeds.rb file are made, the database should be rebuilt and reloaded from scratch.

Loading test data.

This is data that is required for testing the application. Specifically, it is data that should not appear in the production application.

This data should be loaded through model classes (or using factory_girl or similar) in a ‘rake’ file, for example /lib/tasks/test_data.rake and then load it using the rake task rake app:load_demo_data. Similar to loading seeds.rb, if the test data changes then the database should be reloaded from scratch.

(Note that here the rake file is named /lib/tasks/test_data.rake and the rake task to load the data is rake app:load_demo_data. This would vary based on what you felt was an appropriate name for your project.)

Overall database loading/unloading

The correct way to load data into the database is to use the following rake commands:

rake db:drop db:create db:migrate db:seed app:load_demo_data

As you see, multiple rake commands can be run one after another sequenced on the same line.

This should be able to be done at any time by any person in development. If you make a change to any data, please assume that the above sequence of rake commands could be run at any time and all data could be replaced.

Note also that the above command will load data into the ‘development’ instance of your database. If you need to load (or reload) the production or test environments, then precede this command with the appropriate RAILS_ENV like so:

RAILS_ENV=test rake db:drop db:create db:migrate db:seed app:load_demo_data

Here’s an example of what the rake file /lib/tasks/test_data.rake might look like:

namespace :app do
  desc <<-DESC
    Load testing data.
    Run using the command 'rake app:load_demo_data'
  task :load_demo_data => [:environment] do

  # Only data not required in production should be here.
  # If it needs to be there in production, it belongs in seeds.rb.


  User.create(:login => "test_user", :password => "testpass")
  Category.create(:category => 'Category #1')

  # Other test data should be added here...


Posted in agile, programming, rails, ruby on rails | Tagged , , , , | 4 Comments

Best Quora Answer Ever.

I saw this on Quora today and thought it was the best answer ever.

The question, as you can see, was “Who is the Mayor of Palo Alto as of March 10, 2011?”

The answer, contributed by Mayor Sid Esponisa himself, is “Me.”

Posted in quora | Tagged , , , | 1 Comment

“We don’t get out of bed for less than $10,000 per day.”

“We don’t get out of bed for less than $10,000 per day.”

I really loved this blog post. It hits the nail on the head for a lot of reasons. The writing style is good and catchy. The content is real and valuable. It’s worth checking out if you’re looking to develop income at any level for your business.

Posted in agile, career, leanstartup, personal_insight | Tagged , , | 1 Comment

Overriding the OmniAuth callback url for twitter or facebook oath processing.

A lot of people are now using OmniAuth for Oath processing to connect applications to twitter, facebook, linkedin or any number of other SAAS applications. It’s easy and it works well.

I’m using it for some work I’m doing with a client of mine (Practically Green – a great little eco-startup) and ran into an issue with how it created callback url’s — the url where the user is redirected after the Oauth authentication is completed.

The issue was with the way our web listeners are proxied back to the rails application servers. Behind the scenes, the rails application servers have a host name of something that’s not really a valid domain name (say, something like ‘railsserver’).

Omniauth was grabbing this value from the request object and forwarding our users back to an Oauth callback url like ‘http://railsservers/auth/twitter/…’. Obviously, this isn’t what we wanted — the Oauth callbacks were failing.

After digging through the Omniauth code, I ran across the offending piece of code:

 def full_host
  case OmniAuth.config.full_host
   when String
   when Proc
    uri = URI.parse(request.url.gsub(/\?.*$/,''))
    uri.path = ''
    uri.query = nil

Basically, if this config paramerter :full_host isn’t set to either a string or a proc, omniauth pulls the uri from the request object — this is where it was messing up.

Since the Omniauth config object is a singleton, I just set that parameter in config/initializers/omniauth.rb like so:

(in config/initializers/omniauth.rb)
# Set the default hostname for omniauth to send callbacks to.
OmniAuth.config.full_host = ""

With this, the full_host param is a string and now the redirects are always created to come back to where we want.

Posted in agile, leanstartup, programming, rails, twitter | Tagged , , , , | 8 Comments

What are the best ways to recruit top engineering talent to work on a pre-Series A startup with no funding but big ideas?

I saw this question on Quora and it caught my eye because it’s focused on the area I’m interested in professionally — how to build and launch new businesses that make a real impact.

One of the answers, though, I think got it all wrong:

“Selling the engineer on the vision is key, but it doesn’t need to be the same part of the vision that you think is exciting. You may have to frame it differently in terms the engineer will understand as valuable to their learning and reputation as an engineer.

Want to eliminate third world debt through micro-finance? Ok…that’s great but might not excite an engineer. It involves implementing a machine learning algorithm to arbitrage risks based on someone’s social graph? That might be a wee bit more exciting for an engineer to implement.

Finally, just get them to help you with a very small part of the problem. If you can get them to write a few lines of code, odds are a good engineer will not be personally satisfied until it is a 1000 line elegant solution. At that point, they have sold themselves on the project.”

I have to be honest, I’m not sure I agree with this approach. It may work to sell some engineers, but not the engineer that can bring your vision to reality.

‘frame it differently in terms the engineer will understand as valuable to their learning and reputation as an engineer.’ – this is just not accurate. An engineer capable of bringing your vision to reality needs to clearly see *your* vision and buy into it. If you get them excited about a technical solution that they think will make them more valuable, what happens when the technical solution needs to change? Are they still bought in?

You and the technical founder need to be aligned on what the vision and the value are. And a good engineer for that stage in a business’ life is one that can see your vision and also see the way to make it real.

And this sentence to be honest is a bit insulting and niave – ” If you can get them to write a few lines of code, odds are a good engineer will not be personally satisfied until it is a 1000 line, elegant solution.”

A good engineer is satisfied when the solution fits the problem, not when they have a 1000 line elegant solution. Engineers that ‘over engineer’ in the name of finding elegant solutions will kill your startup.

It’s better to enlist them as a full partner with the whole team focusing appropriate levels of resources to achieve a clear business end. Great engineers are those who can do that. And they exist.

Posted in agile, leanstartup, management, personal_insight | Leave a comment

Should I work at a large company or at a startup?

I worked for a couple large companies doing development early in my career. There main frustrations I felt were:

1. Raises were based more on how the company was doing rather than individual contribution. I remember one year my entire department was given a 4% raise. Everyone got the same regardless of how hard they worked.

2. Risk taking was only rewarded if things worked out for the best. Trying a new technology that ended up not working (even the failure didn’t impact delivery schedules or business goals) would result in a negative at review time. It encouraged people to not suggest new approaches or technologies in case they didn’t work. It was great for people who played it safe and didn’t try new things.

3. Management was always working to reduce development cost — meaning they worked to outsource our work if they could. I was in a meeting once where the CIO told my team he could probably outsource our work to a 3rd world country for 10-20% of what he paid us. What an ass.

On the flip side, many of the people I worked with are still there and have had stable salaries and good benefits in a job where they didn’t have to work that hard for years at a stretch.

I guess what’s best depends on what you want from your career and how driven you are to create new things and work on the edge of technology. Personally, I work now with startups and love that I’m always on the edge of what’s new.

Posted in agile, career, leanstartup, management | 2 Comments

Question: Should I plan for the future? Or focus on what I need to do today? Answer: Yes.

Being able to focus on what you need to have in place for the future is a good thing. It’s good in that you can’t be successful without it.

The challenge is that thinking 3 steps ahead too often will get you into trouble as you can lose site of the things you need to execute on today.

I’ve always said the hardest thing in business (especially in a startup) is to ‘execute effectively today while also building tomorrow’. Most people have it in their nature to do one or the other.

To be really successful, you need to do both. At the same time.

Posted in leanstartup, management, personal_insight, scrum | Tagged , , | Leave a comment

Top 10 Best Resources to learn Ruby on Rails

I have a lot of people ask me about resources to help them learn and come up to speed on rails. I found this list of resources on Quora recently and thought it was worth reposting here to give it a wider audience. I’ve also annotated the list a bit to say something about each entry.

Why’s (Poignant) Guide to Ruby

Why’s (Poignant) Guide to Ruby is a classic. It’s done in an the format of a graphic novel and contains a lot of fun and interesting material. It was done by Why the Lucky Stiff, a cult figure in the ruby community that you should know about.

Rails for Zombies by EnvyLabs

A fun and entertaining guide to ruby on rails. Be careful, you may find yourself craving brains and entrails for lunch if you finish this one — though your rails skills will be better off for the effort.

Try Ruby!

An easy to use place to begin learning about Ruby (Not so much about rails, tho). It’s a great place to start if you are literally starting from scratch.

Ruby on Rails Tutorial

This is a non-free resource, but is well done and may be worth investing in if you are serious about learning the material. Highly recommended.

Ruby Koans

Ruby Koans is an interesting and insightful set of lessons on Ruby (not rails) that focuses on teaching through a set of unit tests. One of it’s strengths is that it introduces you immediately to the value and practice of unit testing — a critical skill and a core value of the ruby community.

The Rails API Docs

If you’re going to be a rails programmer, you need to have this url handy. Have a question on the :belongs_to statement? Want to understand the call-back lifecycle for active record model classes? It’s all here. Not for beginners, but definitely required before you’re ready to call yourself a master.


On of the best and one of my favorite resources on rails. Railscasts are an important resource for the entire rails community. They are a series of free — and very useful — videos on various topics in rails development, complete with source code. Want to know about Ajax calls? Want to understand the latest in authentication libraries? It’s all here.


RailsBridge is an effort to build community around helping people learn rails. It’s people helping people. You can find a mentor there, get involved with something in your community, learn by volunteering time to a non-profit. It’s a valuable resource.


Ruby Learning is a site put together by Satish Talim, a senior software consultant based in Pune, India. He’s done a thorough job of providing lessons on many aspects of the ruby language. The site is a bit over-done with adsense and other advertising, but there’s a lot of meat there too.

Peepcode Screencasts

Peepcode Screencasts are another well-known resource in the rails community. Similar to Railscasts, they publish a regular series of videos on different aspects of rails development. The screencasts aren’t free, but considering the time they could save you they could be a great investment in terms of getting you up to speed fast. They’re widely known and recommended.

Posted in lists, programming, ruby on rails | 2 Comments

What is a fair salary for a technical co-founder in a startup?

Here’s the question: “If you’re a software engineer or developer and your asked to do a project for a lean startup to incubate and you’re asked to reduce your price in exchange for equity, what ratio of discount to equity is reasonable. An example might be a 50% discount for 30% in the company.”

If you’re going to be a co-founder and receive equity on par with the other co-founders, it seems appropriate that you should receive income on par with them as well.

In other words, it depends on how much cash is available. ‘Co-founders’ that get significant ownership should receive similar ‘salaries’ initially.

So rather than think of things in terms of how much of a discount against salary you should ask for, I think it would be more appropriate to think in terms of what you bring to the table — and what the others are bringing. Then, see what cash is available for you all to share.

If you want more cash than others, then you should be prepared to get less equity. Some technical co-founders take no salary at all in return for more equity.

Co-founders that bring money to the table in addition to time would be right to ask for a greater equity stake.

Posted in leanstartup, management, programming | Leave a comment