Angular:
http://angularjs.org/
by scott_in_ct
HTML
<div ng-controller="MyCtrl">
<label>Enter more numbers/characters to test:</label><br/>
<input type="text" ng-model="thisNum" clean-field>
<h3>thisNum is {{thisNum}}</h3>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.directive('cleanField', function(uppercaseFilter) {
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
var sanitize = function(inputValue) {
var clean = "";
if (inputValue) {
clean = inputValue.replace(/[^\d.]+/g, '');
if (clean != inputValue) {
modelCtrl.$setViewValue(clean);
modelCtrl.$render();
}
}
return clean;
};
modelCtrl.$parsers.push(sanitize);
sanitize(scope[attrs.ngModel]); //runs on load
}
};
});
function MyCtrl($scope) {
$scope.thisNum = '8asdf0';
}