邮箱正则校验
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; }
以上是关于邮箱正则校验的主要内容,如果未能解决你的问题,请参考以下文章