本文整理汇总了PHP中Respect\Validation\Validator::stringType方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::stringType方法的具体用法?PHP Validator::stringType怎么用?PHP Validator::stringType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::stringType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
public function isValid($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
if (isset($_REQUEST[$name])) {
$rules = explode("|", $value);
foreach ($rules as $rule) {
$exploded = explode(":", $rule);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::stringType()->length($min)->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be at least " . $min . " characters long";
}
break;
case 'email':
if (Valid::email()->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be a valid email ";
}
break;
case 'equalTo':
if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
$errors[] = "Values do not match";
}
break;
default:
//do nothing
}
}
} else {
$errors = "No value found";
}
}
return $errors;
}
示例2: set
/**
* Saves a setting as a key/value pair
*
* Settings specific to fast-forward start with a `ff.` prefix.
*
* You can use the constants of this class to avoid looking up the key names.
*
* @param string $key Unique key name.<br>
* Must contain only letters (a-z, A-Z), digits (0-9) and "."
* @param string $value
*
* @throws \Exception
*/
public function set($key, $value)
{
$out = $this->client->getOutput();
try {
v::stringType()->alnum('.')->noWhitespace()->notEmpty()->assert($key);
} catch (NestedValidationException $e) {
$out->error($e->getFullMessage());
return;
}
$setting = $this->get($key, true);
if ($setting === null) {
$setting = new Setting();
$setting->key = $key;
}
$oldValue = $setting->value;
$setting->value = $value;
if (!$this->validate($setting)) {
return;
}
if ($oldValue === null) {
$out->writeln("Inserting new setting:\n{$key} = <options=bold>{$value}</>");
} elseif ($oldValue !== $value) {
$out->writeln("Changing setting:\n{$key} = {$oldValue} --> <options=bold>{$value}</>");
} else {
$out->writeln("Setting already up-to-date:\n{$key} = {$value}");
}
$setting->save();
}
示例3: isValid
public function isValid($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
$rules = explode("|", $value);
foreach ($rules as $rule) {
$exploded = explode(":", $rule);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::stringType()->length($min, null)->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be at least " . $min . " characters long!";
}
break;
case 'email':
if (Valid::email()->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be a valid email address!";
}
break;
case 'equalTo':
if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
$errors[] = "Value does not match verification value!";
}
break;
default:
$errors[] = "No value found!";
}
}
}
return $errors;
}
示例4: isValid
public function isValid($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
$exploded = explode(":", $value);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::stringType()->length($min, null)->Validate($_REQUEST[$name]) == false) {
$errors[] = $exploded[2] . " must be at least " . $min . " characters long ";
}
break;
case 'email':
if (Valid::email()->Validate($_REQUEST[$name]) == false) {
$errors[] = "Please enter a valid email";
}
break;
case 'equalTo':
if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
$errors[] = $exploded[2] . " value does not match " . $exploded[3] . " value";
}
break;
default:
//do nothing
$errors[] = "No values found";
}
}
return $errors;
}
示例5: initRule
/**
* init valid rule
*/
protected function initRule()
{
$this->validRule['id'] = v::numeric();
$this->validRule['name'] = v::stringType()->length(1, 10);
$this->validRule['email'] = v::email();
$this->validRule['sex'] = v::intVal()->between(0, 1);
}
示例6: charsInMemory
/**
* Returns the number of characters in memory after parsing given string.
* @param string $string
* @return int
* @throws ParseException
*/
public static function charsInMemory($string)
{
if (!Validator::stringType()->regex('/".*"/')->validate($string)) {
throw new ParseException('String must be surrounded by double quotes (")');
}
return preg_match_all("/(\\\\\\\\|\\\\\"|\\\\x[[:xdigit:]]{2}|.)/", substr($string, 1, strlen($string) - 2));
}
示例7: validateName
protected function validateName()
{
$value = v::stringType()->notEmpty()->validate($this->getName());
if (!$value) {
msg::showMsg('O campo Nome deve ser preenchido corretamente.' . '<script>focusOn("name");</script>', 'danger');
}
return $this;
}
示例8: setCityDistance
/**
* Sets the distance between two {@link City}s
* @param string $cityA name of city
* @param string $cityB name of city
* @param int $distance distance between cities
*/
public function setCityDistance($cityA, $cityB, $distance)
{
Validator::stringType()->notBlank()->check($cityA);
Validator::stringType()->notBlank()->check($cityB);
Validator::intType()->positive()->check($distance);
$this->adjacencyMatrix[$cityA][$cityB] = $distance;
$this->adjacencyMatrix[$cityB][$cityA] = $distance;
}
示例9: validatePatchVars
public function validatePatchVars($vars)
{
$validations = [v::intVal()->validate($vars['id']), v::stringType()->length(2)->validate($vars['nome']), v::stringType()->length(2)->validate($vars['sobrenome'])];
if ($vars['nascimento']) {
$validations[] = v::date()->validate($vars['nascimento']);
}
return $validations;
}
示例10: initRule
/**
* init valid rule
*/
protected function initRule()
{
$this->validRule['uid'] = v::numeric();
$this->validRule['expid'] = v::numeric();
$this->validRule['firmName'] = v::stringType()->length(1, 32);
$this->validRule['indCatNo'] = v::stringType()->length(1, 32);
$this->validRule['jobName'] = v::stringType()->length(1, 32);
$this->validRule['areaNo'] = v::stringType()->length(1, 32);
}
示例11: testRespectValidatorsAreCallable
public function testRespectValidatorsAreCallable()
{
$filter = v::key('cake', v::stringType());
static::assertTrue($filter(['cake' => 'a string']));
static::assertTrue($filter(['cake' => 'a string', 'other']));
static::assertFalse($filter(['cake' => 12]));
static::assertFalse($filter([]));
static::assertFalse($filter(['other']));
}
示例12: init
/**
* Initialise rules
*/
public function init()
{
// name validator
$this->rules['name'] = Validator::stringType()->setName('Your full name')->notEmpty()->length(1, 32);
// email validator
$this->rules['email'] = Validator::email()->setName('Email');
// comment validator
$this->rules['comment'] = Validator::stringType()->setName('Comment')->notEmpty();
}
示例13: postValidator
private function postValidator($post = array())
{
try {
v::stringType()->notEmpty()->length(1, 32)->assert($post['name']);
v::stringType()->notEmpty()->length(1, 32)->assert($post['password']);
} catch (vn $exception) {
$this->MSG->showmsg(nl2br($exception->getFullMessage()));
}
}
示例14: nextMember
/**
* Generates the next member in the look-and-say sequence
* @param string $member the current member
* @return string
*/
public function nextMember($member)
{
Validator::stringType()->notEmpty()->check($member);
$next = '';
preg_match_all("/((\\d)\\2*)/", $member, $matches);
foreach ($matches[0] as $match) {
$next .= strval(strlen($match)) . substr($match, 0, 1);
}
return $next;
}
示例15: defineLogin
public function defineLogin($login)
{
$loginValidador = Validator::stringType()->notEmpty()->noWhitespace()->length(8, 120);
try {
$loginValidador->check($login);
$this->login = $login;
} catch (ValidationException $exception) {
print_r($exception->getMainMessage());
}
}