Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
use Respect\Validation\Validator as v;
/**
*
* @throws \Respect\Validation\Exceptions\ValidationException (actually superclass of \InvalidArgumentException)
*/
function createUserEntity($username, $firstName, $lastName, $age, $heightCm, $married, $email, $comment){
v::alnum()->noWhitespace()->length(1,15)->check($username);
v::stringType()->noWhitespace()->length(1,255)->check($firstName);
v::stringType()->noWhitespace()->length(1,255)->check($lastName);
v::intVal()->between(18, 100)->check($age);
v::numericVal()->between(80.5, 249.9)->check($height);
v::boolType()->check($married);
v::email()->check($email);
v::stringType()->length(1)->check($comment);
// do some useful stuff with data
// ...
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.