JS验证文本框输入一个或多个Email Format _JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > JS验证文本框输入一个或多个Email Format

JS验证文本框输入一个或多个Email Format

 2011/9/22 8:13:22  wt75037  http://wt75037.iteye.com  我要评论(0)
  • 摘要:functionCheckEmail(obj)2{3varregEmail=/^[a-zA-Z0-9_\.]+@[a-zA-Z0-9-]+[\.a-zA-Z]+$/;//Email45if(typeof(obj)=="undefined")6{7alert("Theobjectisnotexist!");8returnfalse;9}10elseif(obj.value.replace(//g,"").replace(//g,"")=="")11{12obj.focus();13alert
  • 标签:for 一个
function CheckEmail(obj)
2          {
3            var regEmail = /^[a-zA-Z0-9_\.]+@[a-zA-Z0-9-]+[\.a-zA-Z]+$/; //Email
4                      
5            if(typeof(obj) == "undefined")
6            {
7               alert("The object is not exist!");
8               return false;
9            }
10            else if(obj.value.replace(/ /g,"").replace(/ /g,"") == "")
11            {
12                obj.focus();
13                alert("Please input the email!");
14                return false;
15            }
16            else
17            {
18                var t = obj.value.lastIndexOf(",");    
19                switch(t)
20                {
21                   case -1:
22                   if(regEmail.test(obj.value) == false)
23                    {
24                      obj.focus();
25                      alert("Invalid email type!");
26                      return false;
27                    }
28                   break;
29                   case obj.value.length - 1:
30                      obj.focus();
31                      alert("The comma is the last char,please remove it!");
32                      return false;
33                   break;                 
34                   default:
35                     var emailArray = obj.value.split(",");
36                     for(var i=0; i<=emailArray.length-1; i++)
37                     {
38                       if(regEmail.test(emailArray[i]) == false)
39                       {
40                         obj.focus();
41                         alert("Have invalid email type!\r\n" + emailArray[i]);
42                         return false;
43                       } 
44                     }
45                  }
46               }
47            }
发表评论
用户名: 匿名