-2

Can someone explain this to me !!!, it's the same code but in plunker works, but locally not. In ng-pattern or pattern html5 , Why??????

The first Image is my local server and I put "011.11". This is an error for me, because I need two digits before the dot and two digits after the dot, but the pattern validation not work.

The second image is plunker, and I put "011.11" and there work's.

Plunker Code

<input type="text" name="kilometros" ng-model="calculator.KmEvaluables"  pattern="^([0-9]{0,2}).[0-9]{1,2}$" />
<div ng-show="calculatorForm.kilometros.$error.pattern">Not valid number!</div>

result

enter image description here

My code

<input type="number" name="kilometros" class="form-control" placeholder="ejemplo: 00.00" pattern="^([0-9]{0,2}).[0-9]{1,2}$"  ng-model="calculator.KmEvaluables" required>
<span class="btn btn-danger" ng-show="calculatorForm.kilometros.$error.pattern ">Not valid number !</span>

result

enter image description here validation not work

I put the backslash before the dot patter, but still not working.

The question is..., Why in plunker work's and locally not?.

pokaxperia
  • 87
  • 2
  • 9
  • link to that plunker would help. Also, one has `type="number"` and the other `type="text"` - not sure if that makes a difference. Do you have `calculatorForm` in both? – New Dev Aug 18 '15 at 17:04
  • the type of input doesn't matter, still working with number or text input. I need the plunker validation, but when I copy on my own code, not work, as you can see the images. – pokaxperia Aug 18 '15 at 17:07
  • the plunker code is the correct, the question is, why not work in my local server, if a put the same code – pokaxperia Aug 18 '15 at 17:09
  • Link the plunkr? Are are you sure those bootstrap classes aren't overriding stuff? – ajmajmajma Aug 18 '15 at 17:10
  • @pokaxperia, in fact the type of input does matter - try typing "011.11" into each box: http://plnkr.co/edit/gAAl7ETyvDTTFN1TY1Kj?p=preview – New Dev Aug 18 '15 at 17:17
  • New Dev check this, the plunker not work http://plnkr.co/edit/jCYj97?p=preview. Now check this and it work's https://regex101.com/#javascript. Can you see the difference? – pokaxperia Aug 18 '15 at 17:44
  • Again... one has `` and another has `` The one with `type="number"` gets parsed into a float number, thus removing redundant zeros. For example, the string `"011.11000"` taken from the input is converted to a number `11.11`. This is something that Angular is doing. Only then the pattern validator gets a hold of it, but at that time it passes. – New Dev Aug 19 '15 at 03:59

1 Answers1

0

It might have to do with you locale preferences. Since I saw some Spanish text in your example, you probably use comma to separate the decimal digits in the browser is getting this information when running your code on your local server. It's just a hint...

Jodevan
  • 732
  • 1
  • 6
  • 20