angular.module('myApp.filters', []).
filter('restrict', function () {
return function(input) {
if(input.isNumber)
return input;
else
return 'must enter a number';
}
});
2. you could write a filter that does something like this for the comma question.
angular.module('myApp.filters', []).
filter('comma', function () {
return function(input) {
input += '';
x = input.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2; }
});
Or were you just asking to add these types of filters to the Angular.JS library?
On Thu, Jun 28, 2012 at 10:31 AM, Teren Teh
<ter...@gmail.com> wrote:
Hey there,
I'm wondering if AngularJS provides anything that allows me to restrict input in a textbox? I've had a look at the API and the regex only performs validation - does it also do restrictions? I'd also like to add something that converts the user's input (i.e. when they enter a number greater than 1000, a comma gets added like 1,000).
Thanks!
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/XsCMkGKr0zcJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.
--
Josh Kurz
Head of Web Development
SEO
Social Media
Digital Photography
Internet Marketing