Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Valitron\Validator as Validate;
- //Test 1, valid input
- $v = new Validate(['name' => 'myemail@gmail.com']);
- //We are optional, not needed to be included in data array
- $v->rule('optional', 'name')
- //But if we are included, then we have to be valid email address
- ->rule('email', 'name')->message('Wrong EMAIL format');
- //Print result
- print "Result 1";
- var_dump($v->validate());
- var_dump($v->errors());
- //Test 2, invalid input, it is not email and it is not minlength 10 characters
- $v = new Validate(['name' => '']);
- //We are optional, not needed to be included in data array
- $v->rule('optional', 'name')
- //But if we are included, then we have to be valid email address
- ->rule('email', 'name')->message('Wrong EMAIL format')
- //And email length must be at least 10 characters
- ->rule('lengthMin', 'name', 10)->message('Too small');
- //Print result
- print "Result 2";
- var_dump($v->validate());
- var_dump($v->errors());
- //Test 2, valid input, "name" does not exists in data array
- $v = new Validate([]);
- //We are optional, not needed to be included in data array
- $v->rule('optional', 'name')
- //But if we are included, then we have to be valid email address
- ->rule('email', 'name')->message('Wrong EMAIL format')
- //And email length must be at least 10 characters
- ->rule('lengthMin', 'name', 10)->message('Too small');
- //Print result
- print "Result 3";
- var_dump($v->validate());
- var_dump($v->errors());
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement