AngularJS Simple Example
Input validation
HTML
<div ng-app ng-controller="LoginController">
<div>Hello {{ user.firstName }}</div>
<input ng-model="user.firstName" />
</div>
JavaScript
function LoginController($scope) {
$scope.user = {
firstName: ""
};
$scope.$watch('user.firstName', function(){
console.log("changed");
var cache = $scope.user.firstName;
if (!(/^[a-zA-Z]+$/.test($scope.user.firstName[0]))){
$scope.user.firstName = cache.slice(1,cache.length);
console.log("here: "+ cache)
}
})
}