JSFiddle - React, Tailwind, and code Playground

by jmpp77

HTML

<textarea name="" id="emails" cols="50" rows="10">Emails écrits n'importe comment :
[email protected], [email protected]
et aussi [email protected]
</textarea><br>

<input type="button" id="formater" value="Formater dans le champs">

JavaScript

var emails = document.getElementById('emails');
var formater = document.getElementById('formater');

// Expression régulière permettant de reconnaître une adresse email d'après le standard RFC5322 :
// c.f. http://emailregex.com/
var emailRegexp = /((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))/g;

formater.onclick = function() {
		emails.value = emails.value.match(emailRegexp).join(",\n");
};