The GeoDirectory phone field accepts any text by default. To allow only numbers, give the field a validation pattern.
- Go to Places > Settings > Custom Fields and open the Phone field.
- Show the advanced settings.
- In Validation Pattern, enter a regular expression.
[0-9]+allows digits only.[+]?[0-9 ]{6,20}allows an optional plus sign at the start, then 6 to 20 digits and spaces. - In Validation Message, enter the text people see when the number doesn’t match, such as “Please enter numbers only.”
- Save the field.
The pattern has to match the whole value. With the second example, +44 1234 567890 is accepted and 01234-567890 is not.
The check runs in the visitor’s browser when they submit the add listing form. Numbers that are already saved, or that arrive another way such as a CSV import, are not checked.
The same Phone field settings are where you change the label, the placeholder or whether the field is required. Adding options to GeoDirectory custom fields covers the field settings in general.