-1

I want to create regex for use in JavaScript where minimum 10 digit number is only allowed and maximum 15 digit. It may optionally have "+" at the start only and not at any other places.

Robin
  • 21
  • 4

2 Answers2

0

You can use the following expression

^\+?\d{10,15}$

See a demo on regex101.com.

Jan
  • 42,290
  • 8
  • 54
  • 79
0

I believe this can do the work

var patt = new RegExp("^([+]([0-9]){10,15}$)|^(([0-9]){10,15})$");
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
bruce lui
  • 3
  • 1
  • @esqew Actually, the solution works, it was formatted poorly. – Wiktor Stribiżew Apr 23 '20 at 19:47
  • @WiktorStribiżew seems my comment is a bit misleading after your edit - the `+` token in v1 of this answer would have thrown an error. – esqew Apr 23 '20 at 19:55
  • @esqew It was like this all the time, my edit was fixing the formatting, I just added a newline and 4 spaces before `patt`, see [history](https://stackoverflow.com/posts/61393504/edit/baf89752-09cc-4b49-8f3c-fcef2ac50b58) – Wiktor Stribiżew Apr 23 '20 at 20:01
  • @WiktorStribiżew Right - my mistake. I've deleted my original comment and rescinded my downvote as such. – esqew Apr 23 '20 at 20:04