javascript验证邮箱格式代码
来源:互联网 发布:值乎下载 编辑:程序博客网 时间:2024/04/20 02:53
用一个正侧表达式在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代码验证邮箱格式是否正确 //邮箱验证
- Javascript 正则验证 Email 邮箱的格式
- javaScript验证代码(用户名,密码,邮箱)
- javaScript验证代码(用户名,密码,邮箱)
- Javascript:表单验证(验证空值/邮箱格式)
- JavaScript表单验证和邮箱格式验证的方法
- 验证邮箱格式
- js验证邮箱格式
- 验证邮箱格式
- 邮箱验证格式
- 邮箱格式验证
- 邮箱格式验证 js
- 验证邮箱 电话号码格式
- 邮箱格式的验证
- php验证邮箱格式
- 程序是设计出来的
- Perl数组的应用
- Android平台下实现渐变效果
- 如何写extjs 的多条件搜索框
- 嵌入式linuxTCP/IP路由器
- javascript验证邮箱格式代码
- Session原理
- undefined macro: AM_CONFIG_HEADER solution
- 为mysql的用户赋予权限
- android加载include
- 图像处理滤波器(三)——高斯平滑滤波器(Gaussian Smoothing Filter)
- Android实现图片的倒影效果
- RejectedPolicy--DiscardOldestPolicy
- linux下fork的使用一