<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Phone Number Validation</title>
		<link>https://legacy.forums.gravityhelp.com/topic/phone-number-validation</link>
		<description>Gravity Support Forums Topic: Phone Number Validation</description>
		<language>en-US</language>
		<pubDate>Mon, 20 Apr 2026 07:06:57 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/phone-number-validation" rel="self" type="application/rss+xml" />

		<item>
			<title>Chris Hajer on "Phone Number Validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/phone-number-validation#post-101287</link>
			<pubDate>Tue, 11 Dec 2012 13:30:09 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">101287@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I've heard back from the lead developer.   We provide the hook to change the phone format so that we do not have to add phone formats for every country to the code.  You seem to have used the hooks well and properly, and your code will serve as a template for others who would like to do the same thing.  We will keep your suggestion in mind.  Thank you.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chris Hajer on "Phone Number Validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/phone-number-validation#post-100923</link>
			<pubDate>Mon, 10 Dec 2012 13:44:13 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">100923@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I will bring this topic to the attention of the development team.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Advokat on "Phone Number Validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/phone-number-validation#post-100366</link>
			<pubDate>Sat, 08 Dec 2012 17:19:01 +0000</pubDate>
			<dc:creator>Advokat</dc:creator>
			<guid isPermaLink="false">100366@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I know it's not that smart, but if a phonenumber is required to have a specific format, for further process of the form, it's quite a vital feature.&#60;/p&#62;
&#60;p&#62;I see you dit not implement the code above, although it wouldn't have done anything but improved your plugin (and made some peoples lives a bit easier, including mine ;-))&#60;/p&#62;
&#60;p&#62;This leads me to the question of what it takes to get something implemented into the core of gravity forms, since providing you with the code, and not just a simple, &#34;I need this feature&#34; request?&#60;/p&#62;
&#60;p&#62;Kind regards.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chris Hajer on "Phone Number Validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/phone-number-validation#post-90379</link>
			<pubDate>Mon, 12 Nov 2012 21:42:11 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">90379@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thank you for that code.  However, we don't recommend making changes to the plugin files as those changes will be lost between versions when you upgrade the plugin.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Advokat on "Phone Number Validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/phone-number-validation#post-90050</link>
			<pubDate>Mon, 12 Nov 2012 04:11:17 +0000</pubDate>
			<dc:creator>Advokat</dc:creator>
			<guid isPermaLink="false">90050@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;A preview of the result:&#60;br /&#62;
&#60;a href=&#34;http://cl.ly/image/3Y13041i0b3f&#34; rel=&#34;nofollow&#34;&#62;Result preview, with danish phonenumber&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Advokat on "Phone Number Validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/phone-number-validation#post-90047</link>
			<pubDate>Mon, 12 Nov 2012 04:07:16 +0000</pubDate>
			<dc:creator>Advokat</dc:creator>
			<guid isPermaLink="false">90047@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;I've seen around that people are having an issue trying to validate phone numbers, so i came up with a backwards compatible solution for validating phone numbers.&#60;/p&#62;
&#60;p&#62;------------------------------------&#60;br /&#62;
plugins/gravityforms/forms_model.php&#60;/p&#62;
&#60;p&#62;What To Do:&#60;br /&#62;
Add this function below get_input_masks&#60;br /&#62;
in RGFormsModel class. It's&#60;br /&#62;
located around line 1463.&#60;br /&#62;
------------------------------------&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;public static function get_phone_formats() {

    $formats = array(
    	&#38;#39;standard&#38;#39; =&#38;gt; array(
        	&#38;#39;regex&#38;#39; =&#38;gt; &#38;#39;/^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/&#38;#39;,
        	&#38;#39;name&#38;#39; 	=&#38;gt; &#38;#39;Standard&#38;#39;,
        	&#38;#39;mask&#38;#39;	=&#38;gt; &#38;#39;(###)### - ####&#38;#39;
        )
    );

    return apply_filters(&#38;#39;gform_phone_formats&#38;#39;, $formats);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;------------------------------------&#60;br /&#62;
plugins/gravityforms/form_detail.php&#60;/p&#62;
&#60;p&#62;What To Do:&#60;br /&#62;
Replace the current selectbox named&#60;br /&#62;
field_phone_format to render a box&#60;br /&#62;
based on get_phone_formats. It's&#60;br /&#62;
located around line 1572.&#60;br /&#62;
------------------------------------&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;select id=&#38;quot;field_phone_format&#38;quot; onchange=&#38;quot;SetFieldPhoneFormat(jQuery(this).val());&#38;quot;&#38;gt;
	&#38;lt;option value=&#38;quot;international&#38;quot;&#38;gt;&#38;lt;?php _e(&#38;quot;International&#38;quot;, &#38;quot;gravityforms&#38;quot;); ?&#38;gt;&#38;lt;/option&#38;gt;
	&#38;lt;?php
	$formats = RGFormsModel::get_phone_formats();
    foreach($formats as $format_key =&#38;gt; $format_details){
    	if((!isset($format_details[&#38;#39;regex&#38;#39;]) &#124;&#124; empty($format_details[&#38;#39;regex&#38;#39;])) &#124;&#124; ((!isset($format_details[&#38;#39;mask&#38;#39;]) &#124;&#124; empty($format_details[&#38;#39;mask&#38;#39;])) &#38;amp;&#38;amp; (!isset($format_details[&#38;#39;name&#38;#39;]) &#124;&#124; empty($format_details[&#38;#39;name&#38;#39;])))) continue;
    	$name  = (isset($format_details[&#38;#39;name&#38;#39;]) &#38;amp;&#38;amp; !empty($format_details[&#38;#39;name&#38;#39;])) ? ((isset($format_details[&#38;#39;mask&#38;#39;]) &#38;amp;&#38;amp; !empty($format_details[&#38;#39;mask&#38;#39;])) ? $format_details[&#38;#39;name&#38;#39;] .&#38;#39;: &#38;#39;. $format_details[&#38;#39;mask&#38;#39;] : $format_details[&#38;#39;name&#38;#39;]) : $format_details[&#38;#39;mask&#38;#39;] ;
        ?&#38;gt;
        &#38;lt;option value=&#38;quot;&#38;lt;?php echo $format_key; ?&#38;gt;&#38;quot;&#38;gt;&#38;lt;?php echo $name; ?&#38;gt;&#38;lt;/option&#38;gt;
        &#38;lt;?php
    }
    ?&#38;gt;
&#38;lt;/select&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;------------------------------------&#60;br /&#62;
plugins/gravityforms/form_display.php&#60;/p&#62;
&#60;p&#62;What To Do:&#60;br /&#62;
Replace the current validation method&#60;br /&#62;
used to validate phone numbers. It's&#60;br /&#62;
located around line 1173.&#60;br /&#62;
------------------------------------&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;$formats 	= RGFormsModel::get_phone_formats();
$regex 		= $formats[$field[&#38;quot;phoneFormat&#38;quot;]][&#38;#39;regex&#38;#39;];

if(!empty($value) &#38;amp;&#38;amp; !preg_match($regex, $value)){
    $field[&#38;quot;failed_validation&#38;quot;] = true;
    if(!empty($field[&#38;quot;errorMessage&#38;quot;]))
        $field[&#38;quot;validation_message&#38;quot;] = $field[&#38;quot;errorMessage&#38;quot;];
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;------------------------------------&#60;br /&#62;
themes/yourtheme/functions.php&#60;/p&#62;
&#60;p&#62;What To Do:&#60;br /&#62;
You need to add this to your&#60;br /&#62;
functions.php file to add your own&#60;br /&#62;
custom phoneformats.&#60;br /&#62;
------------------------------------&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;function add_phone_formats($formats) {
    $formats[&#38;quot;danishphone&#38;quot;] = array(
    	&#38;#39;regex&#38;#39; =&#38;gt; &#38;#39;/[0-9]{8}/&#38;#39;,
    	&#38;#39;name&#38;#39; 	=&#38;gt; &#38;#39;Danske Telefonnumre&#38;#39;,
    	&#38;#39;mask&#38;#39;	=&#38;gt; &#38;#39;########&#38;#39;
    );
    return $formats;
}
add_filter(&#38;quot;gform_phone_formats&#38;quot;, &#38;quot;add_phone_formats&#38;quot;);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;------------------------------------&#60;br /&#62;
Whats left?&#60;br /&#62;
------------------------------------&#60;/p&#62;
&#60;p&#62;Now you just have to find your phone&#60;br /&#62;
field, select the correct phone format&#60;br /&#62;
you want to validate. And thats it.&#60;/p&#62;
&#60;p&#62;Please note that the default validation&#60;br /&#62;
message is &#34;hardcoded&#34; in gravity forms&#60;br /&#62;
so to display a validation error upon&#60;br /&#62;
form submit, you need to add whatever&#60;br /&#62;
message to &#34;Validation Message&#34; in&#60;br /&#62;
advanced settings.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
