大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索
打印 上一主题 下一主题

Javascript 验证Email的格式,使用Regex

[复制链接]
跳转到指定楼层
1#
发表于 2011-4-8 15:36:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Javascript 验证Email的格式,使用Regex
validate email address is below:
  1. <script type="text/javascript">

  2. function RegexEmail(emailInputBox){   
  3.    var emailStr = document.getElementById(emailInputBox).value;  
  4.    var emailRegexStr = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  5.    var isvalid = emailRegexStr.test(emailStr);

  6.    if (!isvalid) {
  7. alert('Invalid email address!');
  8. emailInputBox.focus;
  9. }
  10. }

  11. </script>

  12. <input name="emailInput" id="emailInput" maxlength="60" />
  13. <input id="btn1" type="button" value="Validate Email" onclick="return RegexEmail('emailInput')" />
复制代码

手机版|大马资讯论坛  

GMT+8, 2024-4-25 22:08 , Processed in 0.015780 second(s), 11 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表