c# - validate if multiple email address entered in a textbox does not contain a comma in between -


i got regular expression adding comma in between emails.... not getting validation if email address not separated comma.show validation if multiple email addresses not contain comma.and if 1 email address there no comma needed.

you this:

string input  = "a@b.de, c@x.com, f@d.org,"; string[] adresses = input.split(',');  foreach(string adress in adresses){     if (!adress 1 email adress){ //your single-adress validation here       //error     } }  //input valid 

as enigmativity lined out, , in local part valid, if wrapped in " - approach not work.

then, 1 option remaining:

  • consider input string malformated time, , fix it.
  • match every pattern valid email adress according convention.
  • buildup valid string out of these:

something like:

string input = "a@b.de,t@s.com x@y.org;f@m.net";  regex r = new regex("\\w+\\@\\w+"); //your pattern here, example. matchcollection mc = r.matches(input);  list<string> adresses = new list<string>(); foreach (match m in mc) {     adresses.add(m.groups[0].tostring().trim()); }  string sanitizedinput = string.join(", ", adresses); console.writeline(sanitizedinput); //"a@b.de, t@s.com, x@y.org, f@m.net"; console.read(); 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -