Title: Zip code number restriction
Last modified: February 17, 2020

---

# Zip code number restriction

 *  Resolved [jimfr](https://wordpress.org/support/users/jimfr/)
 * (@jimfr)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/zip-code-number-restriction/)
 * hello I would like to know if there is the possibility in the custom fields to
   restrict the entry of the zip code to only 5 digit
 * thank you for your reply

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Alessandro Tesoro](https://wordpress.org/support/users/alessandrotesoro/)
 * (@alessandrotesoro)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/zip-code-number-restriction/#post-12446903)
 * Hi [@jimfr](https://wordpress.org/support/users/jimfr/)
 * Yes that’s possible with a little custom coding. Please copy and paste the following
   snippet into your theme’s functions.php file – at the bottom of it.
 *     ```
       function pno_validate_zipcode( $fields ) {
   
       	if ( isset( $fields['listing_zipcode'] ) ) {
   
       		$max       = 5;
       		$message   = 'Your error message goes here';
       		$validator = new PNO\Validator\LessThanEqual( $max, $message );
   
       		$fields['listing_zipcode']['validators'] = $validator;
   
       	}
   
       	return $fields;
   
       }
       add_filter( 'pno_listing_submission_form_fields', 'pno_validate_zipcode' );
       add_filter( 'pno_listing_editing_form_fields', 'pno_validate_zipcode' );
       ```
   
 * You should also customize the error message within the $message variable.
 * Hope this helps 🙂
 *  Thread Starter [jimfr](https://wordpress.org/support/users/jimfr/)
 * (@jimfr)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/zip-code-number-restriction/#post-12447126)
 * Thanks [@alessandrotesoro](https://wordpress.org/support/users/alessandrotesoro/)
   very good !
 *  [moklet](https://wordpress.org/support/users/moklet/)
 * (@moklet)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/zip-code-number-restriction/#post-12729267)
 * I copied the exact same code, but it always fails ?
 *  [moklet](https://wordpress.org/support/users/moklet/)
 * (@moklet)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/zip-code-number-restriction/#post-12729274)
 * Never mind, this is the validator which worked
 * PNO\Validator\Length
 * the less then equal one compares a numeric e.g the value must be less than 5

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Zip code number restriction’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posterno_56128e.svg)
 * [Posterno - Listings Directory & Classifieds](https://wordpress.org/plugins/posterno/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posterno/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posterno/)
 * [Active Topics](https://wordpress.org/support/plugin/posterno/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posterno/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posterno/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [moklet](https://wordpress.org/support/users/moklet/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/zip-code-number-restriction/#post-12729274)
 * Status: resolved