Documentation
Class libraries
valid
Class library for data validation
File: tokernel.framework/lib/valid.lib.php
Library methods
mixed alpha(string $data)
Check, is string contains only alpha
// Returns 'hello'
$result = $this->lib->valid->alpha('hello');
// Returns false
$result = $this->lib->valid->alpha('number 55.');
mixed az_09(string $data)
Check string is alpha-numeric with underscores and dashes.
// Returns 'test_55'
$result = $this->lib->valid->az_09('test_55');
// Returns false
$result = $this->lib->valid->az_09('test 55 !');
mixed between(int $data, int $a, int $b)
Check value between a, b values.
// Returns 55
$result = $this->lib->valid->between(55, 1, 100);
// Returns false
$result = $this->lib->valid->between(161, 1, 100);
mixed credit_card(mixed $data)
Check is valid credit card. Return card type if number is valid.
Return values: visa, mastercard, amex, discover, diners
// Return 'visa'
// Some numbers is hidden
$result = $this->lib->valid->credit_card('4847****0051****');
// Return false
$result = $this->lib->valid->credit_card('2847958400515861');
mixed digits(int $data [, int $min = -1 ][, int $max = -1])
Check is integer, with string type.
// Return 55
$result = $this->lib->valid->digits('55');
// Return 55
$result = $this->lib->valid->digits('55', '1', '100');
// Return false
$result = $this->lib->valid->digits('198', '1', '100');
mixed email(string $data)
Check is valid e-mail address.
// Return name@example.com
$result = $this->lib->valid->email('name@example.com');
// Return false
$result = $this->lib->valid->email('name_com');
mixed http_host(string $data)
Check is valid host name.
// Return 'example'
$result = $this->lib->valid->http_host('example');
// Return 'example.com'
$result = $this->lib->valid->http_host('example.com');
// Return 'test.example.com'
$result = $this->lib->valid->http_host('test.example.com');
// Return false
$result = $this->lib->valid->http_host('http://example.com');
mixed id(mixed $data [, int $min = 1])
Check is valid id. By default, min = 1.
// Return 55
$result = $this->lib->valid->id(55);
// Return false
$result = $this->lib->valid->id(0);
$result = $this->lib->valid->id('test');
mixed ip(string $data)
Check is valid IP Address.
// Return '192.168.0.1'
$result = $this->lib->valid->ip('192.168.0.1');
// Return false
$result = $this->lib->valid->ip('192.168.0');
$result = $this->lib->valid->ip('19216801');
mixed password(mixed $data [, int $min = 6 ][, int $max = 128])
Check is valid password (with 6-128 chars by default).
// Return 'abc#123&P'
$result = $this->lib->valid->password('abc#123&P');
// Return false
$result = $this->lib->valid->password(123);
mixed password_strength(mixed $data [, int $min = 6 ][, int $max = 128])
Check password strength and return level.
Return values:
-1 = not match
1 = weak
2 = not weak
3 = acceptable
4 = strong
// Return 1 (weak)
$result = $this->lib->valid->password_strength('123');
// Return 2 (not weak)
$result = $this->lib->valid->password_strength('123abc');
// Return 4 (strong)
$result = $this->lib->valid->password_strength('123#T!abc-99');
bool required(mixed $data [, int $min = -1 ][, int $max = -1])
Check data with required length.
// Return true
$result = $this->lib->valid->required('hello');
// Return false
$result = $this->lib->valid->required('');
$result = $this->lib->valid->required('hello', 1, 4);
mixed username(mixed $data [, int $min = 6 ][, int $max = 128])
Check is valid username with 6-128 chars. Will start with char A-Z, a-z.
// Return 'myusername'
$result = $this->lib->valid->username('myusername');
// Return false
$result = $this->lib->valid->username('123');
// Return false
$result = $this->lib->valid->username('1testingwithnumber');
See also: Filter class library.