Search code examples
angularjsvalidationng-pattern

Regex, AngularJS validation


I'm using this pattern to restrict user to use only numbers with max 5 decimals, but it gets valid only when user inputs ' , ' as decimal point, but i want to make it that user can insert ' . ' too, code :

ng-pattern="/^[0-9]+(\.[0-9]{1,5})?$/"

Solution

  • What you want is the parenthesis and pipe. Like this: "(.|,)" This is saying that either a period or comma can be used here.

    http://regexr.com/3da8k