1) onkeyup send textarea values to script
2) converts textarea value to array
3) loops thru the array
4) uses regex to check if its an email address
5) changes inner html of recipient div
Count E-mails in textarea
LastMitch commented: Thanks for the sharing! +12
<script>
function countaddresses(obj){
lineas = 0;
var string = obj.value;
var array = string.split('\n');
var regMail = /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/;
for (i = 0; i < array.length; i++) {
if(regMail.test(array[i]) == true) {
lineas++;
}
}
document.getElementById('lemails').innerHTML=lineas;
}
</script>
<textarea name="emails" class="widel" onkeyup="countaddresses(this)"></textarea>
<div id="lemails"></div>
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.