你要写全来:
<form name=form1> 注意这里要为form加上一个name,强烈建议不要有form这样的关键字
<input type=text name=email> 注意要有这么一个name=email的输入框!!<input type=button value=检查 onclick=cc()>
</form>
<script language=javascript>
function cc()
{
if ((form1.email.value=="")||
(form1.email.value.indexOf('@',0)==-1)||
(form1.email.value.indexOf('.',0)==-1)||
(form1.email.value.length<6))
{
alert ("请你输入合法的email地址!");
form1.email.select();
form1.email.focus();
return false;
}
}
</script>
<form name=form1> 注意这里要为form加上一个name,强烈建议不要有form这样的关键字
<input type=text name=email> 注意要有这么一个name=email的输入框!!<input type=button value=检查 onclick=cc()>
</form>
<script language=javascript>
function cc()
{
if ((form1.email.value=="")||
(form1.email.value.indexOf('@',0)==-1)||
(form1.email.value.indexOf('.',0)==-1)||
(form1.email.value.length<6))
{
alert ("请你输入合法的email地址!");
form1.email.select();
form1.email.focus();
return false;
}
}
</script>
function isEmail(str)
{
// are regular expressions supported?
var supported = 0;
if (window.RegExp) {
var tempStr = "a";
var tempReg = new RegExp(tempStr);
if (tempReg.test(tempStr)) supported = 1;
}
if (!supported)
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
return (!r1.test(str) && r2.test(str));
}
《JSP中email格式的判断》
------
Email Validation The following code is a sample of some characters you can check are in an email address, or should not be in an email address. It is not a complete email validation program that checks for all possible email scenarios, but can be added to as needed.
/*
* Checks for invalid characters
* in email addresses
*/
public class EmailValidation {
public static void main(String[] args)
throws Exception {
String input = "@sun.com";
//Checks for email addresses starting with
//inappropriate symbols like dots or @ signs.
Pattern p = Pattern.compile("^\\.|^\\@");
Matcher m = p.matcher(input);
if (m.find())
System.err.println("Email addresses don't start" +
" with dots or @ signs.");
//Checks for email addresses that start with
//www. and prints a message if it does.
p = Pattern.compile("^www\\.");
m = p.matcher(input);
if (m.find()) {
System.out.println("Email addresses don't start" +
" with \"www.\", only web pages do.");
}
p = Pattern.compile("[^A-Za-z0-9\\.\\@_\\-~#]+");
m = p.matcher(input);
StringBuffer sb = new StringBuffer();
boolean result = m.find();
boolean deletedIllegalChars = false; while(result) {
deletedIllegalChars = true;
m.appendReplacement(sb, "");
result = m.find();
} // Add the last segment of input to the new String
m.appendTail(sb); input = sb.toString(); if (deletedIllegalChars) {
System.out.println("It contained incorrect characters" +
" , such as spaces or commas.");
}
}
}
<!--
Function isMailAddr(thisStr)
Dim regEx, Matches,patrn
on error resume next
Set regEx = New RegExp
isMailAddr=false
patrn="^[A-Za-z0-9_-]+[@]{1}([A-Za-z0-9_-]+[.]{1}[A-Za-z0-9_-]+)+$"
regEx.Pattern = patrn
regEx.IgnoreCase = true
regEx.Global = True
Matches = regEx.test(thisStr)' ok:True else:False
if err then
if instr(thisStr,"@")=0 or instr(thisStr,".")=0 then
isMailAddr=False
else
isMailAddr=true
end if
else
isMailAddr = Matches
end if
End Function
-->
</script>
String.prototype.isEmail=function(){
var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$";
var re = new RegExp(regu);
return ((this.search(re)!=-1)?true:false);
}
用法:
var sss="[email protected]";
alert(sss.isEmail());
function isValidEmail( str ){
if (str.indexOf ('@',0) == -1 || str.indexOf ('.',0) == -1){
return false;
} else
return true;
}
function checkmail(mail)
var strr;
re=/(\w+@\w+\.\w+)(\.{0,1}\w*)(\.{0,1}\w*)/i;
re.exec(mail);
if (RegExp.$3!=""&&RegExp.$3!="."&&RegExp.$2!=".") strr=RegExp.$1+RegExp.$2+RegExp.$3
else
if (RegExp.$2!=""&&RegExp.$2!=".") strr=RegExp.$1+RegExp.$2
else strr=RegExp.$1
if (strr!=mail) {alert("请填写正确的邮件地址;return false}
return true;
}
</script>