AngularJS Example:
HTML
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<div ng-app>
<h2>Name/Email Thingy</h2>
<div ng-controller="TodoCtrl">
<h1>
Everything:
</h1>
<ul class="unstyled">
<li ng-repeat="user in users">
<span>Firstname: {{user.firstname}}, Lastname: {{user.lastname}}, email: {{user.email}}</span>
</li>
</ul>
<form ng-submit="getEmailAndNames()">
<input type="text" ng-model="theUserInput" size="30"
placeholder="felix,fritz,mail@a.com">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
</div>
CSS
.done-true {
text-decoration: line-through;
color: grey;
}
JavaScript
function TodoCtrl($scope) {
$scope.users = [
{
firstname: '',
lastname: '',
email: ''
}
];
$scope.getEmailAndNames = function() {
// Get the string
var content = $scope.theUserInput;
// Split string at every comma, which makes every comma seperated value an array element
var array = content.split(',');
// For every array element as long as there are at least 3 left
while(array.length > 2) {
// Take first 3 array element (e.g. felix, fritz, mail@a.com) and assign it to variables: first, last and email
const [first, last, email] = array.splice(0,3);
// Do your email verification here ...
// then push to array all together:
$scope.users.push({
firstname: first,
lastname: last,
email: email
});
}
$scope.theUserInput = '';
};
}