javascript验证邮箱格式
来源:互联网 发布:天刀捏脸数据明星 编辑:程序博客网 时间:2024/04/29 14:09
用一个正侧表达式在javascript中验证就是咯!
<script language='javascript'>
function chkMail(){
if(document.form1.email.value=''){
alert("请填写邮箱地址!");
document.form1.email.focus();
return false;
}
//开始验证
var email = document.form1.email.value;
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(/.[a-zA-Z0-9_-])+/;
chkFlag = pattern.test(email);
if(chkFlag){
return true;
}
else
{
alert("邮箱地址的格式不正确!");
document.form1.email.focus();
return false;
}
}
</script>
~~~~~~~~~~~~~~~~~~~~~~~完毕!
最简单的就一句:
if(!/^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/.test('email'))
{
alert('email不正确');
}
----------------------------------------------------------------------------------------------------------------------------
js:
function isEmail(email)
{
invalidChars = " /;,:{}[]|*%$#!()`<>?";
if (email == "")
{
return false;
}
for (i=0; i< invalidChars.length; i++)
{
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false;
}
}
atPos = email.indexOf("@",1)
if (atPos == -1) { return false; }
if (email.indexOf("@", atPos+1) != -1) { return false; }
periodPos = email.indexOf(".",atPos)
if(periodPos == -1) {
return false; // and at least one "." after the "@"
}
if ( atPos +2 > periodPos) {
return false; // and at least one character between "@" and "."
}
if ( periodPos +3 > email.length) { return false; }
return true;
}
{
invalidChars = " /;,:{}[]|*%$#!()`<>?";
if (email == "")
{
return false;
}
for (i=0; i< invalidChars.length; i++)
{
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false;
}
}
atPos = email.indexOf("@",1)
if (atPos == -1) { return false; }
if (email.indexOf("@", atPos+1) != -1) { return false; }
periodPos = email.indexOf(".",atPos)
if(periodPos == -1) {
return false; // and at least one "." after the "@"
}
if ( atPos +2 > periodPos) {
return false; // and at least one character between "@" and "."
}
if ( periodPos +3 > email.length) { return false; }
return true;
}
aspx: 调用:
<input id=zz><input type=button value=check onclick="if(isEmail(zz.value))alert('正确');else alert('错误')">
- javascript验证邮箱格式
- javascript验证邮箱格式代码
- javascript验证邮箱格式代码
- Javascript 正则验证 Email 邮箱的格式
- 用户输入验证邮箱,通过javascript代码验证邮箱格式是否正确 //邮箱验证
- Javascript:表单验证(验证空值/邮箱格式)
- JavaScript表单验证和邮箱格式验证的方法
- 验证邮箱格式
- js验证邮箱格式
- 验证邮箱格式
- 邮箱验证格式
- 邮箱格式验证
- 邮箱格式验证 js
- 验证邮箱 电话号码格式
- 邮箱格式的验证
- php验证邮箱格式
- 邮箱/密码格式验证
- java 验证邮箱格式
- 验证码
- 【其他】【RQNOJ】占内存的递归函数
- magento -- 结账时默认选中其中一种配送方式
- javascript验证码(注:不安全)
- VMware ESX主机上虚拟机文件介绍
- javascript验证邮箱格式
- visual studio 2008过期
- PKU1012 Joseph 约瑟夫问题
- 新的征程
- 解决linux下java读取串口之权限问题 No permission to create lock file.
- 微软官方 Platform Builder 5.0 下载地址和SN
- 【贪心】【RQNOJ】排队接水
- 浅谈架构模式
- joj1006(进制转换)