• Resolved jimfr

    (@jimfr)


    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

    (@alessandrotesoro)

    Hi @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

    (@jimfr)

    Thanks @alessandrotesoro very good !

    I copied the exact same code, but it always fails ?

    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.