简体   繁体   中英

email validation in multiline textbox

I have a multiline textbox in which i will be entering many email addresses. how to validate email address at client side for multiple email address. i have used RegularExpressionValidator for validating email in textbox.

thank you

Simply extend the Validator with a loop. Split the textbox string into a array of emails and validate each. In that loop you can feed another array to later screen all wrong emails or abort at the first failed validation.

Something like this:

var mails = textboxcontent.split(';'); // you can also split by blanks. You may also consider the use of trim(str) -> see example below

for(var i = 0, len = mails.length; i < len; i++){
    // check mails[i]
    if(false)
        alert();
}

// or

var failed = '';
for(var i = 0, len = mails.length; i < len; i++){
    // check mails[i]
    if(false)
        failed += mails[i] + ' ';
}

Custom trim implementation (jQuery has a own one if you use it)

function trim (str) {
    return str.replace (/^\s+/, '').replace (/\s+$/, '');
}

Try defining a delimitor which separates emails in the multiline textbox (like ';') and create a regular expression according to the new syntax.

Or

You can read the content of the multiline textbox, split the emails and put the strings in an array or list and validate each one separately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM