Validate Multiple Emails Comma Separated with javascript

后端 未结 9 2076
无人及你
无人及你 2021-01-12 05:03

I want to validate a string which can be an email or multiple emails separated by commas.

For example:

bill.gates@hotmail.com -> TRUE
bill -> FALSE

9条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 06:04

    I used validationEngine and underscore.js to do this:

    function validateEmail(field, rules, i, options) {
    if (!_.all(field.val().split(","), function(candidate) { return $.trim(candidate).match(options.allrules.email.regex); } ))
        return options.allrules.email.alertText;
    }
    

    And then decorated my form field with:

    
    

提交回复
热议问题