本文整理匯總了PHP中Respect\Validation\Validator::float方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::float方法的具體用法?PHP Validator::float怎麽用?PHP Validator::float使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::float方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validateProduct
function validateProduct(&$product)
{
$invalids = array();
if (empty($product['name']) || !Validation::string()->length(1, 255)->validate($product['name'])) {
array_push($invalids, 'name');
}
if (empty($product['price']) || !Validation::float()->min(0, true)->validate($product['price'])) {
array_push($invalids, 'price');
}
if (empty($product['amount']) || !Validation::int()->min(1, true)->validate($product['amount'])) {
array_push($invalids, 'amount');
}
if (empty($product['categoryId']) || !Validation::int()->max(10, true)->validate($product['categoryId'])) {
array_push($invalids, 'categoryId');
}
return $invalids;
}
示例2: validate
/**
* @PrePersist
* @PreUpdate
*/
public function validate()
{
v::float()->assert($this->amount);
v::numeric("+")->startsWith("+")->assert($this->phone);
v::notEmpty()->assert($this->status);
}
示例3: validateCombo
function validateCombo(&$combo)
{
$invalids = array();
if (empty($combo['name']) || !Validation::string()->length(1, 255)->validate($combo['name'])) {
array_push($invalids, 'name');
}
if (empty($combo['price1']) || !Validation::float()->min(0, true)->validate($combo['price1'])) {
array_push($invalids, 'price1');
}
if (empty($combo['amount1']) || !Validation::int()->min(1, true)->validate($combo['amount1'])) {
array_push($invalids, 'amount1');
}
//check if combos 2, 3 or 4 are given
if (!empty($combo['price2']) || !empty($combo['amount2']) || !empty($combo['price3']) || !empty($combo['amount3']) || !empty($combo['price4']) || !empty($combo['amount4'])) {
if (empty($combo['price2']) || !Validation::float()->min(0, true)->validate($combo['price2'])) {
array_push($invalids, 'price2');
}
if (empty($combo['amount2']) || !Validation::int()->min(1, true)->validate($combo['amount2'])) {
array_push($invalids, 'amount2');
}
} else {
$combo['price2'] = $combo['amount2'] = null;
}
//check if combos 3 or 4 are given
if (!empty($combo['price3']) || !empty($combo['amount3']) || !empty($combo['price4']) || !empty($combo['amount4'])) {
if (empty($combo['price3']) || !Validation::float()->min(0, true)->validate($combo['price3'])) {
array_push($invalids, 'price3');
}
if (empty($combo['amount3']) || !Validation::int()->min(1, true)->validate($combo['amount3'])) {
array_push($invalids, 'amount3');
}
} else {
$combo['price3'] = $combo['amount3'] = null;
}
//check if combo 4 is given
if (!empty($combo['price4']) || !empty($combo['amount4'])) {
if (empty($combo['price4']) || !Validation::float()->min(0, true)->validate($combo['price4'])) {
array_push($invalids, 'price4');
}
if (empty($combo['amount4']) || !Validation::int()->min(1, true)->validate($combo['amount4'])) {
array_push($invalids, 'amount4');
}
} else {
$combo['price4'] = $combo['amount4'] = null;
}
return $invalids;
}
示例4: init
public function init()
{
$this->validator = v::attribute('name', v::string()->notEmpty())->attribute('email', v::email())->attribute('description', v::string()->length(5, 50))->attribute('age', v::callback('is_int')->between(0, 100))->attribute('nick', v::string()->alnum()->noWhitespace())->attribute('creditCard', v::numeric()->creditCard())->attribute('accountBalance', v::float())->attribute('banned', v::bool())->attribute('views', v::callback('is_int')->positive());
}