Wednesday, October 10, 2012

use regular expressions in JavaScript

function validateEmail(email) {
   var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
   if (!email.match(pattern)) {
      alert('oh no!');
      return false;
   }
   return true;
}

No comments:

Post a Comment