0

I currently have this regex string and i am getting a Unterminated regular expression literal error in my react code

const check_number = /^[0]\d{10}$)|(^[\+]?[234]\d{12}$

does anyone know how to fix this.

1
  • You could try /^(?:0|\+?[234]\d\d)\d{10}$/ instead Commented Jul 14, 2021 at 6:05

2 Answers 2

1

The exact syntax error is being caused by a missing / ending delimiter (and a few other things). But, your regex has other problems. Use this version:

const check_number = /^(?:0\d{10}|[+]?[234]\d{12})$/

The above pattern matches phone numbers which either:

  • Start with zero and have 11 total digits, or
  • Start with an optional +, followed by 2, 3, or 4, and have 13 total digits
Sign up to request clarification or add additional context in comments.

Comments

-1

The problem is you have an invalid regular expression, for a number of reasons:

  1. You are missing a closing / character at the end
  2. You have a closing parenthesis in the start with no opening parenthesis
  3. You have an opening parenthesis in the middle with no closing paren

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.