-3

I am not a programmer, but I use a system that sometimes requires regex knowledge. I need a custom field on a sign up form on my website. The custom field is only numbers between 10000000 and 29999999. How would I write the expression?

Inigo
  • 12,186
  • 5
  • 41
  • 70
  • 2
    https://www.regular-expressions.info/numericranges.html – Bergi Jan 10 '22 at 02:10
  • 1
    Does this answer your question? [Using regular expressions to validate a numeric range](https://stackoverflow.com/questions/22130429/using-regular-expressions-to-validate-a-numeric-range). In the future please search for your answer before asking a question that has been asked before. – Inigo Jan 10 '22 at 08:01

1 Answers1

1

It'd be something like this:

^[12]\d{7}$

Regex Demo

  • ^ - Matches start of line. Ensuring the next match is the first character of the string.
  • [12] - Checks if the first character is a 1 or 2.
  • \d{7} - Ensures the next 7 characters are 0-9
  • $ - Matches the end of the line. This helps ensures there's nothing after the 7th character that we matched prior.
Mock Coder
  • 189
  • 5