2

I am using jQuery Tag-It. When I enter the tag value, it needs to be validated if it is a valid email address or not. How can I validate this tag using tag-it?

4

1 回答 1

3

干得好!

$(".emails").tagit({
    beforeTagAdded: function(event, ui) {
        return isEmail(ui.tagLabel);
    }
});


function isEmail(email) {
    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return regex.test(email);
}
于 2013-09-27T10:21:03.177 回答