Skip to content

Instantly share code, notes, and snippets.

@yactouat
Created October 27, 2022 12:33
Show Gist options
  • Save yactouat/4fdab4582826b4b47bb723bedbd18e0e to your computer and use it in GitHub Desktop.
Save yactouat/4fdab4582826b4b47bb723bedbd18e0e to your computer and use it in GitHub Desktop.
quick and dirty address validation
<?php
$regex = "/^[\w'\s\p{L}-]*$/u";
$test = preg_match($regex, "8 rue du marché");
$test2 = preg_match($regex, "5 rue de l'apostrophe");
$test3 = preg_match($regex, "10 rue du passage \n à la ligne");
echo "\n";
echo !$test ? "test KO" : "test OK";
echo "\n";
echo "\n";
echo !$test2 ? "test2 KO" : "test2 OK";
echo "\n";
echo "\n";
echo !$test3 ? "test3 KO" : "test3 OK";
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment