本文整理汇总了PHP中Respect\Validation\Validator::alnum方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::alnum方法的具体用法?PHP Validator::alnum怎么用?PHP Validator::alnum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::alnum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _validate
private function _validate($param, $type)
{
$libConfig = $GLOBALS['app']->getConfiguration()->getRawConfiguration('library');
$minNameVal = $libConfig["product"]["minNameLength"];
$maxNameVal = $libConfig["product"]["maxNameLength"];
$minCodeVal = $libConfig["product"]["minCodeLength"];
$maxCodeVal = $libConfig["product"]["maxCodeLength"];
$validateName = v::alnum('-_')->length($minNameVal, $maxNameVal);
$validateCode = v::alnum('-_')->noWhitespace()->length($minCodeVal, $maxCodeVal);
$validateToken = v::alnum('-_');
if (strcmp($type, "name") === 0) {
$isValid = $validateName->validate($param);
if (!$isValid) {
throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_PRODUCT_NAME, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
}
} else {
if (strcmp($type, "code") === 0) {
$isValid = $validateCode->validate($param);
if (!$isValid) {
throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_PRODUCT_CODE, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
}
} else {
if (strcmp($type, "token") === 0) {
$isValid = $validateToken->validate($param);
if (!$isValid) {
throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_TOKEN, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
}
} else {
throw new \InvalidArgumentException('Invalid Validation Type', \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
}
}
}
}
示例2: validateConfig
private function validateConfig(array $config)
{
if (empty($config)) {
throw new \InvalidArgumentException('Empty config is not allowed');
}
$validator = v::arrayVal()->notEmpty()->key('search', v::arrayVal()->notEmpty()->key('uri', v::url()->notEmpty())->key('key', v::alnum()->notEmpty()))->key('data', v::arrayVal()->notEmpty()->key('uri', v::url()->notEmpty())->key('key', v::alnum()->notEmpty()));
$validator->assert($config);
}
示例3: criptografaSenha
public function criptografaSenha($senha)
{
$senhaCriptografada = null;
$senhaValidador = Validator::alnum()->notEmpty()->noWhitespace()->length(4, 20);
try {
$senhaValidador->check($senha);
$senhaCriptografada = md5($senha);
} catch (ValidationException $exception) {
print_r($exception->getMainMessage());
}
return $senhaCriptografada;
}
示例4: output
public function output($request, $response, $args)
{
$query = $request->getQueryParams();
$validator = v::key('a', v::stringType()->length(1, 32))->key('b', v::alnum());
list($ok, $message) = $this->validate($validator, $query);
if (!$ok) {
return $this->view->error('INPUT_ERROR', $message);
}
$ret = array();
for ($i = 0; $i < 4; $i++) {
$ret[] = array('data' => $i);
}
return $this->view->render($ret);
}
示例5: validateAddress
public function validateAddress($address)
{
//@TODO: properly check all types.. strings need to be double checked for alnum, cause of typecasting.
$rules = v::key('firstname', v::notEmpty()->setName('First name'))->key('lastname', v::notEmpty()->setName('Last name'))->key('address', v::alnum(".,-'")->notEmpty()->setName('Address'))->key('secondary_address', v::when(v::notEmpty(), v::alnum(".,-'"), v::alwaysValid())->setName('Address 2'))->key('city', v::alnum()->notEmpty()->setName('City'))->key('state', v::alnum()->notEmpty()->setName('State'))->key('zip', v::when(v::notEmpty(), v::postalCode('US'), v::alwaysValid())->notEmpty()->setName('Zipcode'));
if ($rules->validate($address)) {
return true;
}
try {
$rules->check($address);
} catch (ValidationExceptionInterface $exception) {
// $this->error = $exception->getMainMessage();
}
return false;
}
示例6: test_findMessages_should_apply_templates_to_flattened_messages
public function test_findMessages_should_apply_templates_to_flattened_messages()
{
$stringMax256 = v::string()->length(5, 256);
$alnumDot = v::alnum('.');
$stringMin8 = v::string()->length(8, null);
$v = v::allOf(v::attribute('first_name', $stringMax256)->setName('First Name'), v::attribute('last_name', $stringMax256)->setName('Last Name'), v::attribute('desired_login', $alnumDot)->setName('Desired Login'), v::attribute('password', $stringMin8)->setName('Password'), v::attribute('password_confirmation', $stringMin8)->setName('Password Confirmation'), v::attribute('stay_signedin', v::notEmpty())->setName('Stay signed in'), v::attribute('enable_webhistory', v::notEmpty())->setName('Enabled Web History'), v::attribute('security_question', $stringMax256)->setName('Security Question'))->setName('Validation Form');
try {
$v->assert((object) array('first_name' => 'fiif', 'last_name' => null, 'desired_login' => null, 'password' => null, 'password_confirmation' => null, 'stay_signedin' => null, 'enable_webhistory' => null, 'security_question' => null));
} catch (ValidationException $e) {
$messages = $e->findMessages(array('allOf' => 'Invalid {{name}}', 'first_name.length' => 'Invalid length for {{name}} {{input}}'));
$this->assertEquals($messages['allOf'], 'Invalid Validation Form');
$this->assertEquals($messages['first_name_length'], 'Invalid length for "fiif" fiif');
}
}
示例7: saveAction
/**
* @auth-groups users
*/
public function saveAction()
{
if (!empty($_POST['password_new'])) {
try {
v::length(6)->check($_POST['password_new']);
} catch (ValidationException $e) {
$this->flasher->error('Please make sure new password is longer than 6 characters!');
}
if ($_POST['password_new'] !== $_POST['password_new_confirm']) {
$this->flasher->error('New password fields were not identical!');
}
if (!Gatekeeper::authenticate(['username' => $this->user->username, 'password' => $_POST['password_old']])) {
$this->flasher->error('Invalid password. Changes ignored.');
} else {
$this->user->password = $_POST['password_new'];
$this->user->save();
$this->flasher->success('Password updated!');
}
}
if ($_POST['firstname'] != '-') {
try {
v::alnum(' ')->check($_POST['firstname']);
$this->user->firstName = $_POST['firstname'];
$this->user->save();
$this->flasher->success('First name changed.');
} catch (ValidationException $e) {
$this->flasher->error('Name contains invalid characters. ' . $e->getMainMessage());
}
}
if ($_POST['lastname'] != '-') {
try {
v::alnum(' ')->check($_POST['lastname']);
$this->user->lastName = $_POST['lastname'];
$this->user->save();
$this->flasher->success('Last name changed.');
} catch (ValidationException $e) {
$this->flasher->error('Last name contains invalid characters. ' . $e->getMainMessage());
}
}
$this->redirect('/account');
}
示例8: upsertGroupProcessAction
public function upsertGroupProcessAction()
{
$id = $_POST['id'] ?? null;
if ($id && !ctype_digit($id)) {
$this->flasher->error('E01 Invalid group ID: ' . $id);
$this->redirect('/users/groups');
}
$group = null;
if ($id) {
$group = Gatekeeper::findGroupById($id);
if (!$group) {
$this->flasher->error('E02 Invalid group ID: ' . $id);
}
}
try {
v::alnum('-._')->setName('Group name')->check($_POST['name']);
} catch (ValidationException $e) {
$this->flasher->error($e->getMainMessage());
echo $this->twig->render('users/groups/upsert.twig', ['flashes' => $this->flasher->display(), 'group' => $group ?: $_POST]);
return false;
}
if ($group) {
$group->name = $_POST['name'];
$group->description = $_POST['description'];
$group->save();
} else {
Gatekeeper::createGroup($_POST);
if (Gatekeeper::getLastError()) {
$this->flasher->error($this->site['debug'] ? Gatekeeper::getLastError() : "Could not create group!");
echo $this->twig->render('users/groups/upsert.twig', ['flashes' => $this->flasher->display(), 'user' => $group ?: $_POST]);
return false;
}
$this->flasher->success('Successfully created group.');
$this->redirect('/users/groups');
}
}
示例9: UsuarioValido
private static function UsuarioValido($request)
{
$usernameValidator = validator::alnum()->noWhitespace()->length(4, 15);
$escuelaValidator = validator::alnum("()")->length(3, 50);
try {
$usernameValidator->check($request["nick"]);
if (array_key_exists("escuela", $request)) {
$escuelaValidator->check($request["escuela"]);
}
} catch (InvalidArgumentException $e) {
return false;
}
return true;
}
示例10: getOptions
protected function getOptions()
{
return [['module', null, InputOption::VALUE_OPTIONAL, ' name of module.', null, v::alnum('-')->noWhitespace()], ['name', null, InputOption::VALUE_OPTIONAL, ' name of new controller.', null, v::alnum('-')->noWhitespace()]];
}
示例11: getOptions
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [['name', null, InputOption::VALUE_OPTIONAL, 'Name of new project', null, v::alnum('_-')->noWhitespace()], ['path', null, InputOption::VALUE_OPTIONAL, 'Project root path', null, v::directory()->writable()]];
}
示例12: validate
private function validate($input)
{
$validator = v::key('username', v::alnum()->notEmpty()->noWhitespace())->key('password', v::stringType()->notEmpty()->length(3, 20));
$validator->assert($input);
}
示例13: password
/**
*
* @param string $password
* @return boolean
*/
public function password($password) : bool
{
return V::alnum()->noWhitespace()->length(8, null)->validate($password);
}
示例14: setNomePortador
/**
* Seta o nome do portador do cartão
*
* @access public
* @param string $nomePortador
* @return Cartao
*/
public function setNomePortador($nomePortador)
{
if (!v::alnum()->notEmpty()->validate($nomePortador)) {
throw new InvalidArgumentException('Caracteres inválidos no nome do portador.');
}
$this->nomePortador = substr($nomePortador, 0, 50);
return $this;
}
示例15: getOptions
protected function getOptions()
{
return [['name', null, InputOption::VALUE_OPTIONAL, 'The name of module.', null, v::alnum('_-')->noWhitespace()]];
}