Created
October 22, 2014 07:11
-
-
Save cheng470/ae9350d649a5020d3a66 to your computer and use it in GitHub Desktop.
正则例子
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>RegExp Validate Demo</title> | |
</head> | |
<body> | |
<input type="text" id="txt" name="txt" /> | |
<input type="button" id="btn" value="Validate Email" /> | |
<div id="print"></div> | |
<script type="text/javascript"> | |
window.onload = function() { | |
var txt = document.getElementById("txt"); | |
var btn = document.getElementById("btn"); | |
var print = document.getElementById("print"); | |
var exp = /^\w+@[a-z0-9]+\.[a-z]{2,3}$/i; | |
btn.onclick = function() { | |
print.innerHTML = (exp.test(txt.value)) ? "success" : "failed"; | |
}; | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment