加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式实现邮箱验证的功能

发布时间:2020-12-14 01:30:36 所属栏目:百科 来源:网络整理
导读:.html代码如下: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"htmlheadmeta http-equiv="content-type" content="text/html;charset=gbk"/titleRegExp用法/titlescript type=

.html代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=gbk"/>
<title>RegExp用法</title>

<script type="text/javascript">
	function chkEmail(){
		var email = document.getElementById('email').value;
		var obj = document.getElementById('showMess');
		//www@163.com
		var pattern = /^[a-zA-Z]w+[@]w+[.][w.]+$/;//<pre name="code" class="html">^[a-zA-Z]<span style="font-family: Arial,Helvetica,sans-serif;">表示以字母开头</span>
if(pattern.test(email)){obj.innerText = "正确";obj.style.color = 'green';}else{obj.innerText = "错误";obj.style.color = 'red';}}</script></head><body><label>电子邮件:</label><input type="text" id="email" onblur="chkEmail()"/><span id="showMess"></span></body></html>
 结果如下: 
 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读