Created
April 25, 2013 15:27
-
-
Save oliveagle/5460605 to your computer and use it in GitHub Desktop.
javascript: validate email address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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