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?
Asked
Active
Viewed 54 times
-3
-
2https://www.regular-expressions.info/numericranges.html – Bergi Jan 10 '22 at 02:10
-
1Does 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 Answers
1
It'd be something like this:
^[12]\d{7}$
^
- 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