0

how to validate phone number field in advanced custom field on wordpress.Minimum number and maximum number and type only number.

/^(\d[\s-]?)?[([\s-]{0,2}?\d{3}[)]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i

Leena Mathew
  • 1
  • 1
  • 2
  • Possible duplicate of [A comprehensive regex for phone number validation](https://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation) – niko Oct 16 '17 at 18:34

1 Answers1

0

If you don't want to develop your own code, you can use the Advanced Custom Fields plugin (https://wordpress.org/plugins/validated-field-for-acf/) and then use RegEx to define the allowed phone number pattern for example:

/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i

This pattern will work for a range of phone numbers but you can adapt the RegEx to your specific requirements. There already is a post on phone number validation at: A comprehensive regex for phone number validation

I hope this helps.

Clinton
  • 1,111
  • 1
  • 14
  • 21