Search code examples
angularjsvalidationng-patternangularjs-ng-pattern

How to use ng-pattern to limit 10 number inputs separated by commas


I want to enter in up to 10, 8 character length numbers in one text field all separated by commas. For example, 12345678,12345678,12345678,12345678.....

The only thing is the numbers can only be 8 characters at max and only up to 10 numbers entered at max. I have it to where I can keep entering numbers but I cannot get it to be with those limitations and I need help.

This is what I have right now: ng-pattern="/^([0-9\s])+(,[0-9\s]+)*$/"


Solution

  • Try this pattern:

    ^\d{1,8}(,\d{1,8}){0,9}
    

    And works as follows, first, require 1-8 digits, optionally, require comma, 1-8 digits 0 to 9 times.