Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
quick email validation
function validate(name, email) {
var errors = [];
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(name === '') {
errors.push('You forgot to enter your name');
if(email === '' || !emailReg.test(email)) {
errors.push('Your e-mail address is invalid');
if(errors.length) {
throw errors.join('\n');
var name = $(this).children('input[name="name"]').val();
var email = $(this).children('input[name="email"]').val();
try {
} catch (err) {
return false;

This comment has been minimized.

Copy link

@Paden Paden commented Aug 29, 2012

I have a rule: Store a jQuery object in a var if used more than once. There's no point in creating more jQuery overhead.

var $self =. $(this);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment