Skip to content

Instantly share code, notes, and snippets.

@othonet
Created April 14, 2022 15:11
Show Gist options
  • Save othonet/437b67f655ec5dc80caa9587c4adaff3 to your computer and use it in GitHub Desktop.
Save othonet/437b67f655ec5dc80caa9587c4adaff3 to your computer and use it in GitHub Desktop.
PHP - Validate CEP
<?php
$valor = '18135-690';
if (preg_match('/[0-9]{5,5}([-]?[0-9]{3})?$/', $valor)):
echo 'CEP válido';
else:
echo 'CEP inválido';
endif;
// Saída CEP válido
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment