79674780

Date: 2025-06-21 22:37:47
Score: 0.5
Natty:
Report link

If anyone is still struggling with this in 2025 the regex pattern that works is

"\\(?\\d{3}\\)?-?.?\\s?\\d{3}-?.?\\s?\\d{4}"

for some reason JSX just won't use square brackets properly even when escaping them. It could also be because I have the regex expression in a ternary operator.

pattern={
                name === "phone"
                  ? "\\(?\\d{3}\\)?-?.?\\s?\\d{3}-?.?\\s?\\d{4}"
                  : name === "email"
                  ? "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$"
                  : undefined
              }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Reid