Skip to content

Instantly share code, notes, and snippets.

@oliveagle
Created April 25, 2013 15:27
Show Gist options
  • Save oliveagle/5460605 to your computer and use it in GitHub Desktop.
Save oliveagle/5460605 to your computer and use it in GitHub Desktop.
javascript: validate email address
function isEmailAddr(object) {
var s = document.getElementById(object.id).value;
var pattern = /^[a-zA-Z0-9_\-]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
if (s !== "") {
if (!pattern.exec(s)) {
alert('请输入正确的邮箱地址');
object.value = "";
object.focus();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment