I have become inspired and convinced by the idea of test driven development. Kent Beck said it best when he said –
We write code because that is our work and we write tests so that we know when we are done.
Or something like that.
So I was sitting at my desk and I had to do some AJAX thingy with a form and an email address as the input for a client’s website. It looked pretty straight forward. But how do I give some email validation feedback to the user? I am thinking a regex expression would be nice. But I am not a regex ninja so I might need a few goes at this and how do I know if it works? The last thing I want is to prevent the user from entering valid email addresses – false positives are better than false negatives. Aha! How about I write some tests?
It took me a while and I had a lot of help from this guy’s blog but I came up with a regular expression that passed enough test cases for me to feel satisfied with it. Simply run it in your browser’s developer’s console to see it go.