AngularJS Filter number with fixed length

Sometimes you want a number of a certain length. If it’s not of that length it needs leading zeros. AngularJS provides the number filter. However this lacks the possibility to have leading zeros.

AngularJS is very extendable. You can make your own leading zeros filter in just a few minutes. The creation of a custom AngularJS filter needs three things.

  1. Create a module
  2. Create the filter and his function
  3. Register the module in the application

The AngularJS Filter

The JSFiddle belows shows a filter that gives you leading zeros.

Share this

4 thoughts on “AngularJS Filter number with fixed length

  1. How to make this filter add the zeros dynamically when the user enter numbers in a textbox?

Leave a Reply to HERON DIAS Cancel reply

Your email address will not be published. Required fields are marked *