下面代码在FF中第一次通过验证,当第二次点击“check email”的时候提示出错,请帮忙看看是什么问题。<html>
<head>
<style type="text/css">
* { font-family:Calibri; }
</style></head>
<body> <input type="text" id="uc-email" name="email" size="40" value="[email protected]"/>
<input type="button" value="Check Email" onclick="CheckEmail();" />
<script type="text/javascript">
function CheckEmail() {
var email = document.getElementById("uc-email").value;
if (email != "") {
if (!(/^[a-z][\w.-]+@[\w.-]+.[a-z]+$/gi.test(email))) {
alert("Invalid e-mail address");
}
}
}
</script></body>
</html>
<head>
<style type="text/css">
* { font-family:Calibri; }
</style></head>
<body> <input type="text" id="uc-email" name="email" size="40" value="[email protected]"/>
<input type="button" value="Check Email" onclick="CheckEmail();" />
<script type="text/javascript">
function CheckEmail() {
var email = document.getElementById("uc-email").value;
if (email != "") {
if (!(/^[a-z][\w.-]+@[\w.-]+.[a-z]+$/gi.test(email))) {
alert("Invalid e-mail address");
}
}
}
</script></body>
</html>
function CheckEmail() {
var email = document.getElementById("uc-email").value;
if (email != "") {
if (!(/^[a-z][\w.-]+@[\w.-]+\.[a-z]+$/gi.test(email))) {
alert("Invalid e-mail address");
}
}
}
</script>
<head>
<style type="text/css">
* { font-family:Calibri; }
</style>
<script type="text/javascript">
function CheckEmail() {
var email = document.getElementById("uc-email").value;
if (email != "") {
if (!(/^[a-z][\w.-]+@[\w.-]+.[a-z]+$/gi.test(email))) {
alert("Invalid e-mail address");
}
}
}
</script>
</head>
<body> <input type="text" id="uc-email" name="email" size="40" value="[email protected]"/>
<input type="button" value="Check Email" onclick="CheckEmail();" /></body>
</html>
ff下一直引用的是同一个正则有一些解释
http://bbs.51js.com/thread-78431-1-1.html
多谢,test是单次匹配,而 /g 是多次搜索。