AndrewZhang

有时候碰到在文本框输入一个或多个Email情况,我缺省状态是用","分开。

 1 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            }

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-24
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案