3 final class AlmanacNames
extends Phobject
{
5 public static function validateName($name) {
6 if (strlen($name) < 3) {
9 'Almanac service, device, property, network and namespace names '.
10 'must be at least 3 characters long.'));
13 if (strlen($name) > 100) {
16 'Almanac service, device, property, network and namespace names '.
17 'may not be more than 100 characters long.'));
20 if (!preg_match('/^[a-z0-9.-]+\z/', $name)) {
23 'Almanac service, device, property, network and namespace names '.
24 'may only contain lowercase letters, numbers, hyphens, and '.
28 if (preg_match('/(^|\\.)\d+(\z|\\.)/', $name)) {
31 'Almanac service, device, network, property and namespace names '.
32 'may not have any segments containing only digits.'));
35 if (preg_match('/\.\./', $name)) {
38 'Almanac service, device, property, network and namespace names '.
39 'may not contain multiple consecutive periods.'));
42 if (preg_match('/\\.-|-\\./', $name)) {
45 'Almanac service, device, property, network and namespace names '.
46 'may not contain hyphens adjacent to periods.'));
49 if (preg_match('/--/', $name)) {
52 'Almanac service, device, property, network and namespace names '.
53 'may not contain multiple consecutive hyphens.'));
56 if (!preg_match('/^[a-z0-9].*[a-z0-9]\z/', $name)) {
59 'Almanac service, device, property, network and namespace names '.
60 'must begin and end with a letter or number.'));