I would like to create custom validation for us phone numbers | XM Community
Skip to main content
Solved

I would like to create custom validation for us phone numbers

  • March 22, 2018
  • 3 replies
  • 103 views

sheardln
Level 1 ●
Forum|alt.badge.img+8
I would like to create custom validation so that respondents have to enter their phone number in the following fomat: (xxx)xxx-xxxx. I have tried using a custom validation with a regex statement, but it doesn't seem to work. Am I missing something? Thanks!

Best answer by TomG

If you want to go the custom validation route, here is a simple regex string (doesn't do any checking for valid area code or anything): `^\\([0-9]{3}\\)[0-9]{3}\\-[0-9]{4}$`

3 replies

Michael_Campbell_RedPepper
QPN Level 3 ●●●
Forum|alt.badge.img+3
For sure! What Regex statement did you use? @TomG had a cool library that he uses in Javascript if you're able to use that. It's called Cleave.js. If not, we can get you the right Regex String!

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • Answer
  • March 22, 2018
If you want to go the custom validation route, here is a simple regex string (doesn't do any checking for valid area code or anything): `^\\([0-9]{3}\\)[0-9]{3}\\-[0-9]{4}$`

sheardln
Level 1 ●
Forum|alt.badge.img+8
  • Author
  • Level 1 ●
  • 2 replies
  • March 23, 2018
Thanks to both of you! I was using something similar, but the string that TomG provided works perfectly! Yay!