首页 > 代码库 > 邮箱正则校验

邮箱正则校验

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("aa@qq.com"));      false.should.be.eql(verifyMultipleEmail("aa,@qq.com"));      true.should.be.eql(verifyMultipleEmail("aa@qq.com, cc@163.com"));      false.should.be.eql(verifyMultipleEmail("aa@qq.com, ,cc@163.com"));      false.should.be.eql(verifyMultipleEmail("aa@qq.com, cc@163.com,"));      false.should.be.eql(verifyMultipleEmail(","));      false.should.be.eql(verifyMultipleEmail("@"));      true.should.be.eql(verifyMultipleEmail("lkj_jl@k.com"));    });  });});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;}

  

邮箱正则校验