With pleasure.

My English is not so good,so I paste the code directly:


//copied from http://www.webtoolkit.info/javascript-trim.html
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//I modified the regex.
function validateEmail(field) {
    //var regex=/\b[a-z0-9._%+...@[a-z0-9.-]+\.[a-z]{2,4}\b/i;
    var regex=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return (regex.test(trim(field))) ? true : false;
}
function validateMultipleEmailsCommaSeparated(value) {
    var result = value.split(",");

    alert(result);
    for(var i = 0;i < result.length;i++)
    if(!validateEmail(result[i]))
            return false;
    return true;
}

On Fri, Jul 24, 2009 at 1:14 PM, Mohd.Tareq <tareq.m...@gmail.com> wrote:

> Hi Kuo Yang, *
> *
> *Thanks for your reply.*
> *I am doing the same thing, but if i am entering any other charecter like
> ( _ | ) ( ] [  )*
> *instead of comma, so its considering as a string & after that not able to
> validate it.*
> *
> *
> *I am writing this kind of functions to validate my multiple email value.*
> *
> *
> function validateEmail(field) {
>     var regex=/\b[a-z0-9._%+...@[a-z0-9.-]+\.[a-z]{2,4}\b/i;
>     return (regex.test(field)) ? true : false;
> }
> function validateMultipleEmailsCommaSeparated(value) {
>     var result = value.split(",");
>     for(var i = 0;i < result.length;i++)
>     if(!validateEmail(result[i]))
>             return false;
>     return true;
> }
>
> *By the ways I am hitting to fix this problem of my script.*
>
> *If you have any suggestions for the same then plz let me know ... :)*
>
> *Thanks
> *
> On Thu, Jul 23, 2009 at 7:24 PM, Kuo Yang <daras...@gmail.com> wrote:
>
>> You can split the Emails with the comma, and then validate them one by
>> one.
>>
>>
>>
>> On Thu, Jul 23, 2009 at 9:49 PM, Mohd.Tareq <tareq.m...@gmail.com> wrote:
>>
>>>
>>> Hi Guys,
>>>
>>> Can any one tell me validation ' *Email Validation for multiple emails
>>> (comma separated)* ' for textarea.
>>>
>>> I am writing Regular expression but not able validating the given input
>>> with comma :(
>>>
>>> Please suggest something in JQuery Or Javascript
>>>
>>>
>>> Thanking you....
>>>
>>>
>>>    Regard
>>>
>>> Mohd.Tareque
>>>
>>>
>>
>
>
> --
>   Regard
>
> Mohd.Tareque
>

Reply via email to