uhlryk / angular-dynamic-number

Highly customizable angular directive for numbers
64 stars 32 forks source link

Leading zeroes truncated #42

Closed nmani85 closed 7 years ago

nmani85 commented 7 years ago

I am trying to use dynamic number on Credit Card CVV(security code) field, and the leading zeroes are truncated even though this case is valid. Ex: <input id="cardCVV" name="cardCVV" ng-model="paymentDetails.CreditCard.SecurityCode" class="form-control" type="text" required awnum num-int="4" num-fract="0" num-neg="false" ng-pattern="/^\d{3,4}$/">

How do I retain the leading zeroes?

Thanks, Nevetha

uhlryk commented 7 years ago

Thanks for finding this issue. This module aim mainly for prices and standard numbers. In your case it is more you string consisting of the numbers than normal number. For now this module always removing leading zeros and there is no possibility to stop this.

But I will consider adding option to allow leading zero, because it is relatively easy to add and extend usefulness of this module. I will try sit on this during weekend but Im not guarantee that it will be ready after weekend.

By the way this module may not work correctly with ng-pattern - I didn't tested them both, but my module use some low level methods which may break other directives. And I think you don't need it. What you want you can accomplish only with angular-dynamic-number.

uhlryk commented 7 years ago

It is impossible to not truncate leading zero. It is because this directive return number. Number in javascript doesn't contain leading zeros If you type

var myVar = 00010;

it is equal 10.