0

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]+)*$/"

Cœur
  • 37,241
  • 25
  • 195
  • 267
McMintz
  • 254
  • 6
  • 19

1 Answers1

2

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.

Oli
  • 1,132
  • 1
  • 12
  • 26
  • You are a life saver, thank you so much, it actually worked. I keep forgetting about the digits regex use. I'm still new to this and again thank you very much! For anyone else that has this problem, the full code is ng-pattern="/^\d{1,8}(,\d{1,8}){0,9}?$/" – McMintz Jun 30 '16 at 15:42
  • No problem ar all :-) – Oli Jun 30 '16 at 15:46
  • I had another quick question: if I wanted to add leading zeros how can I do this? So say you put in 1234, the end output would be 00001234 – McMintz Jun 30 '16 at 15:53
  • You could try something like `number = 14; console.log(("00000000" + number).substr(-8,8));` perhaps? – Oli Jun 30 '16 at 16:18