Skip to content

Instantly share code, notes, and snippets.

@Kedrigern
Last active December 16, 2015 11:48
Show Gist options
  • Select an option

  • Save Kedrigern/5429708 to your computer and use it in GitHub Desktop.

Select an option

Save Kedrigern/5429708 to your computer and use it in GitHub Desktop.
Regexp matchich if string with street name has orientation number too.
<?php
/**
*
* Regexp matchich if string with street name has orientation number too.
* Rules are for Czech Republic orientation numbers:
* a) number for 0-999
* b) may be supplemented by one letter
* @link http://www.czso.cz/csu/rso.nsf/i/cislo_orientacni
*
* @author: Ondřej Profant <ondrej.profant <> gmail.com>, 2013
*
*/
$strings = array (
"Šternberkova",
"Šternberkova 10",
"Šternberkova 2350/10",
"Pod Sychrovem II",
"Pod Sychrovem II 30",
"Ulice 29",
"Ulice 29b",
"Ulice 29ab"
);
$pattern = "|(\d)+\w?$|";
foreach( $strings as $s) {
echo( (preg_match($pattern, trim($s)) ? "yes" : "no") . "\t$s\n");
}
@Kedrigern

Copy link
Copy Markdown
Author

V Nette¨forms:

$this->addText("street", "Ulice a č. orientační:")
       ->addRule(Form::MAX_LENGTH, 'Jméno ulice nesmí být delší než %d znaků', 36)
       ->addRule(Form::PATTERN, 'Vyplňte ulici a číslo orientační', '^[\w ]* (\d)+\w?$')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment