Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 231
user740609 Avatar asked May 25 '11 05:05

user740609


1 Answers

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+$/, '');
}
like image 179
sra Avatar answered Sep 28 '22 20:09

sra