Search code examples
javascriptangularjsregexvalidationx-editable

Angular-Xeditable e-pattern not accepting valid regular expression


I am trying to validate the user input of a text field using e-pattern from the angular-xeditable directive. I have built the regular expression using an online regex builder/tester and it does exactly what I want however angular-xeditable doesn't seem to recognize the expression as being valid. It shows the below even when the expression is valid.

requirements:

  • Value must be >= 0.0 or <= 1.0
  • Value can have one or two decimal places
  • First decimal place can be a digit between 0-9
  • Second decimal place should be either 0 or 5

valid entry: 0.5, 0.95, 0.40, 1.0

regex:

 ^((0+(\.[0-9][05]?))|1+(\.0))$

code:

<span e-pattern="/^((0+(\.[0-9][05]?))|1+(\.0))$/" e-required ng-show="!tableform.$visible" editable-text="user.available" e-form="tableform" onbeforesave="checkAvailable($data)">{{ user.available}} </span>

message:

enter image description here

Is there anything I'm missing or need to amend to the expression or span tag?


Solution

  • Fail, I just figured out the issue it's incredibly simple e-pattern does not require /^ or $/ before or after the expression, should instead read:

     e-pattern="((0+(\.[0-9][05]?))|1+(\.0))"