{"id":2886,"date":"2026-10-20T08:37:16","date_gmt":"2026-10-20T07:37:16","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/phone-field-numbers-only\/"},"modified":"2026-10-20T08:37:16","modified_gmt":"2026-10-20T07:37:16","slug":"phone-field-numbers-only","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/how-tos\/phone-field-numbers-only\/","title":{"rendered":"How to make the phone field accept numbers only"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The GeoDirectory phone field accepts any text by default. To allow only numbers, give the field a validation pattern.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to Places &gt; Settings &gt; Custom Fields and open the Phone field.<\/li>\n\n\n\n<li>Show the advanced settings.<\/li>\n\n\n\n<li>In Validation Pattern, enter a regular expression. <code>&#091;0-9&#093;+<\/code> allows digits only. <code>&#091;+&#093;?&#091;0-9 &#093;{6,20}<\/code> allows an optional plus sign at the start, then 6 to 20 digits and spaces.<\/li>\n\n\n\n<li>In Validation Message, enter the text people see when the number doesn&#8217;t match, such as &#8220;Please enter numbers only.&#8221;<\/li>\n\n\n\n<li>Save the field.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The pattern has to match the whole value. With the second example, <code>+44 1234 567890<\/code> is accepted and <code>01234-567890<\/code> is not.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The check runs in the visitor&#8217;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same Phone field settings are where you change the label, the placeholder or whether the field is required. <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/core-features\/adding-options-to-geodirectory-custom-fields\/\">Adding options to GeoDirectory custom fields<\/a> covers the field settings in general.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The GeoDirectory phone field accepts any text by default. To allow only numbers, give the field a validation pattern. 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&#8217;s browser when they submit the add listing form. Numbers [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,432],"class_list":["post-2886","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-how-tos"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=2886"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2886\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2886"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2886"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}