PHP 7.2 버전용으로 올림!
This commit is contained in:
Vendored
+14
@@ -86,6 +86,19 @@ if($v->validate()) {
|
||||
}
|
||||
```
|
||||
|
||||
Or use dot syntax to validate all members of a numeric array:
|
||||
|
||||
```php
|
||||
$v = new Valitron\Validator(array('values' => array(50, 90)));
|
||||
$v->rule('max', 'values.*', 100);
|
||||
if($v->validate()) {
|
||||
echo "Yay! We're all good!";
|
||||
} else {
|
||||
// Errors
|
||||
print_r($v->errors());
|
||||
}
|
||||
```
|
||||
|
||||
Setting language and language dir globally:
|
||||
|
||||
```php
|
||||
@@ -121,6 +134,7 @@ V::lang('ar');
|
||||
* `notIn` - Negation of `in` rule (not in array of values)
|
||||
* `ip` - Valid IP address
|
||||
* `email` - Valid email address
|
||||
* `emailDNS` - Valid email address with active DNS record
|
||||
* `url` - Valid URL
|
||||
* `urlActive` - Valid URL with active DNS record
|
||||
* `alpha` - Alphabetic characters only
|
||||
|
||||
Vendored
+12
-4
@@ -4,7 +4,7 @@
|
||||
"description": "Simple, elegant, stand-alone validation library with NO dependencies",
|
||||
"keywords": ["validation", "validator", "valid"],
|
||||
"homepage": "http://github.com/vlucas/valitron",
|
||||
"license" : "BSD",
|
||||
"license" : "BSD-3-Clause",
|
||||
"authors" : [
|
||||
{
|
||||
"name": "Vance Lucas",
|
||||
@@ -16,11 +16,19 @@
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.5 || ^6.5"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "It can support the multiple bytes string length."
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Valitron": "src/"
|
||||
"psr-4": {
|
||||
"Valitron\\": "src/Valitron"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Valitron\\": "tests/Valitron"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
return array(
|
||||
'required' => "yra privalomas",
|
||||
'equals' => "reikšmė turi būti tokia pati, kaip „%s“",
|
||||
'different' => "turi būti kitokia, nei „%s“",
|
||||
'accepted' => "turi būti priimta",
|
||||
'numeric' => "turi būti sveikasis skaičius",
|
||||
'integer' => "turi būti skaičius",
|
||||
'length' => "turi būti %d ženklų ilgio",
|
||||
'min' => "turi būti bent %s",
|
||||
'max' => "turi būti ne daugiau kaip %s",
|
||||
'in' => "turi neteisingą vertę",
|
||||
'notIn' => "turi neteisingą vertę",
|
||||
'ip' => "nėra teisingas IP adresas",
|
||||
'email' => "nėra teisingas el. pašto adresas",
|
||||
'url' => "nėra teisingas URL",
|
||||
'urlActive' => "turi būti aktyvus domenas",
|
||||
'alpha' => "turi turėti tik raides a-ž",
|
||||
'alphaNum' => "turi turėti tik raides a-ž ir/ar skaičius 0-9",
|
||||
'slug' => "turi turėti tik raides a-ž, skaičius 0-9, brukšnelius ir apatinius brukšnelius",
|
||||
'regex' => "yra neteisingų ženklų",
|
||||
'date' => "nėra teisinga data",
|
||||
'dateFormat' => "turi būti „%s“ formato data",
|
||||
'dateBefore' => "turi būti data, ankstesnė nei „%s“",
|
||||
'dateAfter' => "turi būti data, vėlesnė nei „%s“",
|
||||
'contains' => "turi turėti %s",
|
||||
'boolean' => "turi būti būlio (taip/ne) tipo",
|
||||
'lengthBetween' => "turi būti nuo %d iki %d ilgio",
|
||||
'creditCard' => "turi būti teisingas kreditinės kortelės numeris",
|
||||
'lengthMin' => "turi būti bent %d ženklų ilgio",
|
||||
'lengthMax' => "turi būti ne ilgesnis nei %d ženklų",
|
||||
'instanceOf' => "turi būti „%s“ atvejis"
|
||||
);
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'required' => "är obligatorisk",
|
||||
'equals' => "måste vara samma som '%s'",
|
||||
'different' => "får inte vara samma som '%s'",
|
||||
'accepted' => "måste accepteras",
|
||||
'numeric' => "måste vara numerisk",
|
||||
'integer' => "måste vara ett heltal",
|
||||
'length' => "måste vara %d tecken långt",
|
||||
'min' => "måste vara minst %s",
|
||||
'max' => "får inte vara mer än %s",
|
||||
'in' => "innehåller ogiltigt värde",
|
||||
'notIn' => "innehåller ogiltigt värde",
|
||||
'ip' => "är inte en giltlig IP-adress",
|
||||
'email' => "är inte en giltlig e-postadress",
|
||||
'url' => "är inte en giltlig URL",
|
||||
'urlActive' => "måste vara ett aktivt domännamn",
|
||||
'alpha' => "får bara inehålla bokstäver a-z",
|
||||
'alphaNum' => "får bara inehålla bokstäver a-z och/eller siffror 0-9",
|
||||
'slug' => "får bara inehålla bokstäver a-z och/eller siffror 0-9, bindesträck og understräck",
|
||||
'regex' => "inehåller ogiltliga tecken",
|
||||
'date' => "är inte ett giltligt datum",
|
||||
'dateFormat' => "måste vara ett datum med formatet '%s'",
|
||||
'dateBefore' => "måste vara ett datum före '%s'",
|
||||
'dateAfter' => "måste vara ett datum efter '%s'",
|
||||
'contains' => "måste innehålla %s",
|
||||
'boolean' => "måste vara ett booleskt värde",
|
||||
'lengthBetween' => "måste vara mellan %d och %d tecken långt",
|
||||
'creditCard' => "måste vara et gyldig kredittkortnummer",
|
||||
'lengthMin' => "måste vara minst %d tecken långt",
|
||||
'lengthMax' => "får itne överstiga %d tecken",
|
||||
'instanceOf' => "måste vara en instans av '%s'"
|
||||
);
|
||||
+6
-1
@@ -24,5 +24,10 @@ return array(
|
||||
'dateFormat' => "日期的格式应该为 '%s'",
|
||||
'dateBefore' => "日期必须在 '%s' 之前",
|
||||
'dateAfter' => "日期必须在 '%s' 之后",
|
||||
'contains' => "必须包含 %s"
|
||||
'contains' => "必须包含 %s",
|
||||
'boolean' => "必须是真或假",
|
||||
'lengthBetween' => "长度只能介于 %d 和 %d 之间",
|
||||
'creditCard' => "信用卡号码不正确",
|
||||
'lengthMin' => "长度必须大于 %d",
|
||||
'lengthMax' => "长度必须小于 %d"
|
||||
);
|
||||
|
||||
+51
-8
@@ -77,6 +77,11 @@ class Validator
|
||||
*/
|
||||
protected $validUrlPrefixes = array('http://', 'https://', 'ftp://');
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $stop_on_first_fail = false;
|
||||
|
||||
/**
|
||||
* Setup validation
|
||||
*
|
||||
@@ -173,9 +178,9 @@ class Validator
|
||||
*/
|
||||
protected function validateEquals($field, $value, array $params)
|
||||
{
|
||||
$field2 = $params[0];
|
||||
|
||||
return isset($this->_fields[$field2]) && $value == $this->_fields[$field2];
|
||||
// extract the second field value, this accounts for nested array values
|
||||
list($field2Value, $multiple) = $this->getPart($this->_fields, explode('.', $params[0]));
|
||||
return isset($field2Value) && $value == $field2Value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,9 +194,9 @@ class Validator
|
||||
*/
|
||||
protected function validateDifferent($field, $value, array $params)
|
||||
{
|
||||
$field2 = $params[0];
|
||||
|
||||
return isset($this->_fields[$field2]) && $value != $this->_fields[$field2];
|
||||
// extract the second field value, this accounts for nested array values
|
||||
list($field2Value, $multiple) = $this->getPart($this->_fields, explode('.', $params[0]));
|
||||
return isset($field2Value) && $value != $field2Value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +251,7 @@ class Validator
|
||||
{
|
||||
if (isset($params[0]) && (bool) $params[0]){
|
||||
//strict mode
|
||||
return preg_match('/^-?([0-9])+$/i', $value);
|
||||
return preg_match('/^([0-9]|-[1-9]|-?[1-9][0-9]*)$/i', $value);
|
||||
}
|
||||
|
||||
return filter_var($value, \FILTER_VALIDATE_INT) !== false;
|
||||
@@ -500,6 +505,26 @@ class Validator
|
||||
return filter_var($value, \FILTER_VALIDATE_EMAIL) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a field is a valid e-mail address and the domain name is active
|
||||
*
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateEmailDNS($field, $value)
|
||||
{
|
||||
if ($this->validateEmail($field, $value)) {
|
||||
$domain = ltrim(stristr($value, '@'), '@') . '.';
|
||||
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46')) {
|
||||
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||
}
|
||||
return checkdnsrr($domain, 'ANY');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a field is a valid URL by syntax
|
||||
*
|
||||
@@ -945,6 +970,7 @@ class Validator
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$set_to_break = false;
|
||||
foreach ($this->_validations as $v) {
|
||||
foreach ($v['fields'] as $field) {
|
||||
list($values, $multiple) = $this->getPart($this->_fields, explode('.', $field));
|
||||
@@ -979,13 +1005,26 @@ class Validator
|
||||
|
||||
if (!$result) {
|
||||
$this->error($field, $v['message'], $v['params']);
|
||||
if($this->stop_on_first_fail) {
|
||||
$set_to_break = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($set_to_break) break;
|
||||
}
|
||||
|
||||
return count($this->errors()) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the validation stop a rule is failed
|
||||
* @param bool $stop
|
||||
*/
|
||||
public function stopOnFirstFail($stop = true) {
|
||||
$this->stop_on_first_fail = (bool) $stop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all rule callbacks, the static and instance ones.
|
||||
*
|
||||
@@ -1092,7 +1131,7 @@ class Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if either a valdiator with the given name has been
|
||||
* Returns true if either a validator with the given name has been
|
||||
* registered or there is a default validator by that name.
|
||||
*
|
||||
* @param string $name
|
||||
@@ -1160,6 +1199,8 @@ class Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* Add label to rule
|
||||
*
|
||||
* @param string $value
|
||||
* @internal param array $labels
|
||||
* @return $this
|
||||
@@ -1173,6 +1214,8 @@ class Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* Add labels to rules
|
||||
*
|
||||
* @param array $labels
|
||||
* @return $this
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user