1

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

Votes + Comments
Thanks for the sharing!
<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>
3
Contributors
3
Replies
20
Views
4 Years
Discussion Span
Last Post by LastMitch
0

Just change var regMail = /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/; to

var regMail = /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,7})$/;

Edited by pritaeas: Added markdown.

0

Count E-mails in textarea

This is a nice simple codesnippet. it does it job to count emails in the textares. Thanks for sharing.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.