<?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: ZIP code validation</title>
		<link>https://legacy.forums.gravityhelp.com/topic/zip-code-validation</link>
		<description>Gravity Support Forums Topic: ZIP code validation</description>
		<language>en-US</language>
		<pubDate>Tue, 07 Apr 2026 16:40:08 +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/zip-code-validation" rel="self" type="application/rss+xml" />

		<item>
			<title>Kevin Flahaut on "ZIP code validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/zip-code-validation#post-31840</link>
			<pubDate>Fri, 05 Aug 2011 14:05:08 +0000</pubDate>
			<dc:creator>Kevin Flahaut</dc:creator>
			<guid isPermaLink="false">31840@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;That was easy :) Glad you figured it out.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>JossNL on "ZIP code validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/zip-code-validation#post-31838</link>
			<pubDate>Fri, 05 Aug 2011 12:54:53 +0000</pubDate>
			<dc:creator>JossNL</dc:creator>
			<guid isPermaLink="false">31838@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;And of course you see what you're doing wrong only when you just hit submit.&#60;/p&#62;
&#60;p&#62;ZIP code is not in input_x.3 but in input_x_3&#60;br /&#62;
I was looking at the name, not the ID.&#60;/p&#62;
&#60;p&#62;It's working now!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>JossNL on "ZIP code validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/zip-code-validation#post-31837</link>
			<pubDate>Fri, 05 Aug 2011 12:51:47 +0000</pubDate>
			<dc:creator>JossNL</dc:creator>
			<guid isPermaLink="false">31837@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi there,&#60;/p&#62;
&#60;p&#62;I've been having some troubles with GravityForms... Or users, to be more precise. They seem to be mistaking the ZIP code field for street number. So I decided I need a validation on the ZIP code. Problem is... I use the advanced address field you guys supplied, and I can't get the validation to work on that. Our zip code (postcode) is made up out of 4 numbers, an optional space and 2 letters. The problem is probably in the field id. I tried it with&#60;br /&#62;
&#60;code&#62;$field_value = rgpost(&#38;quot;input_{$field[&#38;#39;id&#38;#39;]}&#38;quot;);&#60;/code&#62;&#60;br /&#62;
and&#60;br /&#62;
&#60;code&#62;$field_value = rgpost(&#38;quot;input_{$field[&#38;#39;id&#38;#39;]}.3&#38;quot;);&#60;/code&#62;&#60;br /&#62;
since the zipcode is in input_x.3&#60;/p&#62;
&#60;p&#62;Both fail. If I use it on a normal text line, the validation does work, but this is not an option.&#60;/p&#62;
&#60;p&#62;Full code:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;#39;gform_validation&#38;#39;, &#38;#39;validate_postcode&#38;#39;);

function validate_postcode($validation_result) {

    $form = $validation_result[&#38;quot;form&#38;quot;];
    $current_page = rgpost(&#38;#39;gform_source_page_number_&#38;#39; . $form[&#38;#39;id&#38;#39;]) ? rgpost(&#38;#39;gform_source_page_number_&#38;#39; . $form[&#38;#39;id&#38;#39;]) : 1;
    foreach($form[&#38;#39;fields&#38;#39;] as &#38;amp;$field){
        if(strpos($field[&#38;#39;cssClass&#38;#39;], &#38;#39;postcode&#38;#39;) === false)
            continue;

        $field_page = $field[&#38;#39;pageNumber&#38;#39;];
        $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());

        if($field_page != $current_page &#124;&#124; $is_hidden)
            continue;

        $field_value = rgpost(&#38;quot;input_{$field[&#38;#39;id&#38;#39;]}.3&#38;quot;);
        $is_valid = is_postcode($field_value);
        if($is_valid)
            continue;

        $validation_result[&#38;#39;is_valid&#38;#39;] = false;
        $field[&#38;#39;failed_validation&#38;#39;] = true;
        $field[&#38;#39;validation_message&#38;#39;] = &#38;#39;De postcode is niet correct ingevuld.&#38;#39;;

    }

    $validation_result[&#38;#39;form&#38;#39;] = $form;
    return $validation_result;
}

function is_postcode($value) {
	if (preg_match(&#38;#39;/^[1-9][0-9]{3} ?[a-zA-Z]{2}$/&#38;#39;, $value)) {
		return true;
	} else {
		return false;
	}
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
