Testing a Form’s Zipcode Field with Regular Expressions to Determine WordPress Page Behaviour

I think you’ve more or less got what you need. You’ve got a textfield in an HTML form. That form needs to sit in a template file somewhere in a WordPress theme. This template file generates uncached pages.

Inside the PHP template for said template file, check the $_POST (or $_REQUEST) object for the form field ID you’ve set in the HTML. Then do your templating logic in the kind of if..else logic block you outline in psudeocode above.

if( isset( $_POST['form_field_id'] ) && validation_function( $_POST['form_field_id'] ) ) {
  //stuff to display to validated zipcodes   
} else {
  //stuff to display to non-validated zipcodes
}

Your validation function can probably go anywhere, but is likely most accessable via functions.php:

function validation_function($text_to_validate) {
   $validation_result = [preg_match][2]("/^92(2|3|5)/",$text_to_validate);
   if( count( $validation_result ) > 1 ) {
      return true;
   } else {
      return false;
   }
}