当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Email的验证源码

Email的验证源码

2020年08月10日  | 移动技术网IT编程  | 我要评论
<script>
		
	function validate_form(thisform) 
	{
		with(thisform)
			{
				if(validate_email(email,"email must be filled out.")==false)
					{
						email.focus;
					}
				else
				{
				alert("validate successful.");
				}
			}
			  
		
	}
	
	function validate_email(field,alerttxt)
	{
		with (field) 
		{
           //验证是否为空
           if (value == null || value == "") 
		     {
             alert(alerttxt);
             return false;
             } 
		   else 
		     {
                  //非空时,验证是否email格式
                  apos = value.indexOf("@");
                  dotpos = value.lastIndexOf(".");
			
                  if (apos < 1 || dotpos - apos < 2) 
		             {
                        alert("Not a valid e-mail address!");
                        return false;
                     } 
		          else 
		             { 
                        return true;
                     }

		      
		    } 
		}
	} 
	
	
</script>
</head>

<body>
<form action="submitpage.htm" onsubmit="return validate_form(this)" method="post">
	
Email:
	<input type="text" name="email" size="30">
    <input type="submit" value="Submit">
</form>
	
</body>

验证Email地址是否符合格式。

本文地址:https://blog.csdn.net/weixin_49884163/article/details/107882869

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网