Esempio n. 1
0
    /**
     * @dataProvider invalidPostalCodesProvider
     */
    public function testShouldNotValidatePatternAccordingToTheDefinedLocale($locale, $postalCode)
    {
        $rule = new PostalCode($locale);

        $this->assertFalse($rule->validate($postalCode));
    }
Esempio n. 2
0
<h3>More Information</h3>
<ul>
    <li><a
    href="https://github.com/Quixotix/PHP-ZipCode-Class">PHP-ZipCode-Class</a>
    source code and downloads on Github.</li>
    <li>My blog post: <a
    href="http://www.micahcarrick.com/php5-zip-code-range-and-distance.html">PHP 5
    Postal Code Range and Distance Calculation</a>.</li>
</ul>
<?php 
include 'PostalCode.php';
// connect to the MySQL database with the zip code table
mysql_connect('localhost', 'YOUR DB USER', 'YOUR PASSWORD');
mysql_select_db('YOUR DB NAME');
// you can instantiate ZipCode with a zip code or with city and state
$portland = new PostalCode("97214");
$ventura = new PostalCode("Ventura, CA");
/*
You can get the distance to another location by specifying a zip code,
city/state string, or another ZipCode object. You can specify whether you want
to get the distance in miles or kilometers.
*/
echo "<h2>Get the distance between 2 zip codes</h2>";
$distance1 = round($portland->getDistanceTo("98501"), 2);
$distance2 = round($portland->getDistanceTo($ventura, PostalCode::UNIT_KILOMETERS), 2);
$distance3 = round($portland->getDistanceTo("Salem, OR"), 2);
echo "Zip code <strong>{$portland}</strong> is <strong>{$distance1}</strong> miles away from " . "zip code <strong>98501</strong><br/>";
echo "Zip code <strong>{$portland}</strong> is <strong>{$distance2}</strong> <em>kilometers</em> away from " . "the city <strong>{$ventura}</strong><br/>";
echo "Zip code <strong>{$portland}</strong> is <strong>{$distance3}</strong> miles away from " . "the city <strong>Salem</strong><br/>";
/*
You can get all of the zip codes within a distance range from teh zip. Here we
Esempio n. 3
0
 /**
  * @expectedException Respect\Validation\Exceptions\PostalCodeException
  * @expectedExceptionMessage "02179-000" must be a valid postal code on "US"
  */
 public function testShouldThrowsPostalCodeExceptionWhenValidationFails()
 {
     $rule = new PostalCode('US');
     $rule->check('02179-000');
 }