邮箱正则校验

Posted 金色元年

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了邮箱正则校验相关的知识,希望对你有一定的参考价值。

var should = require(‘should‘);

describe(‘Array‘, function() {
  describe(‘#indexOf()‘, function() {
    it(‘should return -1 when the value is not present‘, function() {

      true.should.be.eql(verifyMultipleEmail("[email protected]"));
      false.should.be.eql(verifyMultipleEmail("aa,@qq.com"));

      true.should.be.eql(verifyMultipleEmail("[email protected], [email protected]"));
      false.should.be.eql(verifyMultipleEmail("[email protected], ,[email protected]"));
      false.should.be.eql(verifyMultipleEmail("[email protected], [email protected],"));
      false.should.be.eql(verifyMultipleEmail(","));
      false.should.be.eql(verifyMultipleEmail("@"));

      true.should.be.eql(verifyMultipleEmail("[email protected]"));
    });
  });
});



function verifyMultipleEmail(email) {
    var _result = false;
    var _temp = ‘‘;

    if(email.indexOf(‘\,‘) === (-1)) {
        _result = verifyEmail(email);
        return _result;
    }   
    
    var _array = email.split("\,");

    _result = true;
    _array.forEach(function(value, index, full) {
        _temp = value.replace(‘ ‘, ‘‘);
        if(!verifyEmail(_temp)) {
            _result = false;
        } 
    })
    return _result;
}

function verifyEmail(email) {
    var reg = /^[a-z_0-9.-]{1,64}@([a-z0-9-]{1,200}.){1,5}[a-z]{1,6}$/;
    return email.match(reg) ? true : false;
}

  

以上是关于邮箱正则校验的主要内容,如果未能解决你的问题,请参考以下文章

邮箱正则校验

js和java中使用正则表达式校验邮箱

jQuery正则:电话身份证邮箱简单校验

用正则表达式校验手机号,邮箱就是流弊python爬虫入门进阶(08)

Java正则表达式校验QQ号码和邮箱地址格式

常用正则表达式大全(Xss防范sql注入手机邮箱验证等等,持续补充~)