Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-pattern only work in angular 1.2.1, but not on 1.3.17, 1.4.3 and 1.4.4 #12618

Closed
surielmx opened this issue Aug 18, 2015 · 4 comments
Closed

Comments

@surielmx
Copy link

Hello, I have a problem, I trying to validate an input number, setting 00.00. what I need?, only two digits after and before decimal dot, no matter if the two digits after decimal dot are 00.

Between many patterns, I found this that it serves me:
/^\d{0,1}(\d.\d)?\d?$/

I created four examples on plunker with different versions of angularjs, that explain my problem and no matter if set pattern instead ng-pattern attribute, still not working.

Angularjs 1.4.4 http://plnkr.co/edit/K00ffy?p=preview
Angularjs 1.4.3 http://plnkr.co/edit/jCYj97?p=preview
Angularjs 1.3.17 http://plnkr.co/edit/93absW?p=preview
Angularjs 1.2.1 http://plnkr.co/edit/ooFneS?p=preview

The last one works, but my question or the question is, what it's wrong?, me or the versions of AngularJS?.

Thank you.

@kacecode
Copy link

It has to do with the way angular is handling the input -- After your 1.2.1 example the input fed into the pattern validator is a number type instead of a string. Thus, when it's 00000.000000000 it's passed into the validator as 0 then cast to the string "0".

There was a pretty heavy refactor in 1.3 that appears to have added the $parser to the inputDirective which is what is causing your woes.

kacecode added a commit to kacecode/angular.js that referenced this issue Aug 20, 2015
kacecode added a commit to kacecode/angular.js that referenced this issue Aug 20, 2015
Set patternDirective validator to test against viewValue instead of
modelValue.

Closes angular#12344, angular#12618
@Narretz
Copy link
Contributor

Narretz commented Aug 20, 2015

Thanks for opening the issue. It's being tracked here already: #12344

@surielmx
Copy link
Author

Thank you for the answer, but..., the solution is????, or there is no solution ?, so it stays?. Greetings. :)

@kacecode
Copy link

@pokaxperia the fix is the above patch, which you will have to wait on the release of. In the interim, you can get regex matching from a text field

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants