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

标题: Javascript 验证Email的格式,使用Regex [打印本页]

作者: 资讯王    时间: 2011-4-8 15:36
标题: Javascript 验证Email的格式,使用Regex
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')" />
复制代码





欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://www.freeinfo.com.my/) Powered by Discuz! X3.3