本文整理汇总了PHP中Respect\Validation\Validator::numeric方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::numeric方法的具体用法?PHP Validator::numeric怎么用?PHP Validator::numeric使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::numeric方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initRules
/**
* Set items constraints
*
* @return void
*/
public function initRules()
{
$this->rules['no_certificado'] = V::numeric()->noWhitespace()->setName('Numero de certificado');
$this->rules['clave'] = V::notEmpty()->noWhitespace()->setName('Contraseña de la llave privada');
}
示例2: 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);
}
示例3: validate
/**
* @param $cardNumber
* @return array
* @throws NumberValidateException
*/
public static function validate($cardNumber)
{
if (!v::numeric()->noWhitespace()->validate($cardNumber)) {
throw new NumberValidateException();
}
return ['valid' => true, 'type' => 'visa'];
}
示例4: setZipCode
public function setZipCode($value)
{
$value = str_replace('-', '', $value);
if (!v::numeric()->postalCode('BR')->validate($value)) {
throw new FieldRequiredException("CEP é uma informação obrigatória");
}
$this->_zipcode = $value;
}
示例5: 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);
}
示例6: validatePercentage
/**
* Validates that the input is a number and is between 0 and 100 inclusive.
*
* @param float $value
* The value to validate.
*/
protected static function validatePercentage(&$value)
{
if (!isset(self::$percentage)) {
self::$percentage = v::numeric()->min(0, TRUE)->max(100, TRUE);
}
if (is_numeric($value)) {
$value = round($value, 3);
}
self::$percentage->assert($value);
}
示例7: shortcode
public function shortcode($shortcode)
{
if (!Validator::numeric()->length(5)->validate($shortcode)) {
$this->objLogger->addError('Shortcode must be an integer exactly 5 numbers long');
throw new SMSMessageException('Shortcode must be an integer exactly 5 numbers long');
}
$this->shortcode = $shortcode;
$this->objLogger->addDebug('Shortcode has been set to ' . $shortcode);
return $this;
}
示例8: validateCVV
private function validateCVV($parameters)
{
$fieldName = "cvv";
if (array_key_exists($fieldName, $parameters)) {
if (!v::numeric()->validate($parameters[$fieldName]) || !v::length(3, 3, true)->validate($parameters[$fieldName])) {
$this->validationResponse->status = s::VALIDATION_ERROR;
$this->validationResponse->errors[$fieldName] = "is required";
return false;
}
}
return true;
}
示例9: initRule
/**
* init valid rule
*/
protected function initRule()
{
$this->validRule['uid'] = v::numeric();
$this->validRule['eduid'] = v::numeric();
$this->validRule['schoolName'] = v::stringType()->length(1, 32);
$this->validRule['majorName'] = v::stringType()->length(1, 32);
$this->validRule['majorCat'] = v::stringType()->length(1, 32);
$this->validRule['area'] = v::stringType()->length(1, 32);
$this->validRule['schoolCountry'] = v::stringType()->length(1, 32);
$this->validRule['startDate'] = v::date('Y-m');
$this->validRule['endDate'] = v::date('Y-m');
$this->validRule['degreeStatus'] = v::intVal()->between(1, 3);
}
示例10: priceValidate
function priceValidate(&$errors, $price)
{
$priceBlankError = "Вы не указали цену товара";
$priceNotValid = "Цена товара должна быть положительным числом";
if ($price != "") {
$price = filter_var(trim(strip_tags($price)), FILTER_SANITIZE_NUMBER_INT);
if (!v::string()->notEmpty()->validate($price) || !v::numeric()->validate($price) || $price <= 0) {
$errors[] = $priceNotValid;
}
} else {
$errors[] = $priceBlankError;
}
return $price;
}
示例11: postEdit
protected function postEdit($categoryId)
{
$editCategory = $this->collection[$categoryId]->fetch() ?: new stdClass();
foreach ($_POST as $k => $v) {
$editCategory->{$k} = $v;
}
try {
v::object()->attribute('name', v::string()->notEmpty()->length(1, 300))->attribute('enabled', v::numeric()->between(0, 1, true), false)->assert($editCategory);
$this->collection->persist($editCategory);
$this->collection->flush();
header('HTTP/1.1 303 See Other');
header('Location: ' . $_SERVER['REQUEST_URI']);
} catch (NestedValidationExceptionInterface $e) {
return ['editCategory' => $editCategory, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'enabled' => 'Could not enable category'])];
}
}
示例12: __construct
/**
* Create a new RGB from the given red, green and blue channels.
*
* @param float $hue
* Hue is a value between 0 and 360 representing the hue of this colour. If
* a number outside this range is provided it will be wrapped to fit inside
* this range.
* @param float $saturation
* Saturation of this colour.
* @param float $lightness
* Lightness of this colour.
* @param Colour $original
* A colour that this was transformed from.
*/
public function __construct($hue, $saturation, $lightness, Colour $original = NULL)
{
v::numeric()->assert($hue);
Colour::validatePercentage($saturation);
Colour::validatePercentage($lightness);
$this->hue = self::bcfmod($hue, 360, self::$bcscale);
if ($this->hue < 0) {
$this->hue = bcadd($this->hue, 360, self::$bcscale);
}
$this->saturation = bcdiv($saturation, 100, self::$bcscale);
$this->lightness = bcdiv($lightness, 100, self::$bcscale);
$this->chroma = bcmul($this->saturation, bcsub(1, abs(bcmul(2, $this->lightness, self::$bcscale) - 1), self::$bcscale), self::$bcscale);
$this->hsl = $this;
if (isset($original)) {
$this->rgb = $original->rgb;
$this->hsb = $original->hsb;
}
}
示例13: putClientesFornecedoresAction
/**
* Método para atualizar o objeto
* ClientesFornecedores informado
*
* @param Request $request
* @return Response
*/
public function putClientesFornecedoresAction(Request $request, $id)
{
#Validando o id do parâmetro
if (!v::numeric()->validate($id)) {
throw new HttpException(400, "Parâmetro inválido");
}
#Recuperando os serviços
$ClientesFornecedoresRN = $this->get("clientes_fornecedores_rn");
$serializer = $this->get("jms_serializer");
#Recuperando o objeto ClientesFornecedores
$objPessoa = $ClientesFornecedoresRN->find(ClientesFornecedores::class, $id);
#Verificando se o objeto ClientesFornecedores existe
if (!isset($objPessoa)) {
throw new HttpException(400, "Solicitação inválida");
}
#Verificando o método http
if ($request->getMethod() === "PUT") {
#Criando o formulário
$form = $this->createForm(new ClientesFornecedoresType(), $objPessoa);
#Repasando a requisição
$form->submit($request);
#Verifica se os dados são válidos
if ($form->isValid()) {
#Recuperando o objeto ClientesFornecedores
$ClientesFornecedores = $form->getData();
#Tratamento de exceções
try {
#Atualizando o objeto
$result = $ClientesFornecedoresRN->update($ClientesFornecedores);
#Retorno
return new Response($serializer->serialize($result, "json"));
} catch (\Exception $e) {
#Verificando se existe violação de unicidade. (campos definidos como únicos).
if ($e->getPrevious()->getCode() == 23000) {
throw new HttpException(400, "Já existe registros com os dados informados");
}
} catch (\Error $e) {
throw new HttpException(400, $e->getMessage());
}
}
}
#Retorno
throw new HttpException(400, "Solicitação inválida");
}
示例14: __construct
/**
* Create a new RGB from the given red, green and blue channels.
*
* @param float $red
* A value between 0 and 255 for the red channel.
* @param float $green
* A value between 0 and 255 for the green channel.
* @param float $blue
* A value between 0 and 255 for the blue channel.
* @param Colour $original
* A colour that this was transformed from.
*/
public function __construct($red, $green, $blue, Colour $original = NULL)
{
$channel = v::numeric()->numeric()->min(0, TRUE)->max(self::MAX_RGB, TRUE);
$channel->assert($red);
$channel->assert($green);
$channel->assert($blue);
// Store normalised values for channels.
$this->red = bcdiv($red, self::MAX_RGB, self::$bcscale);
$this->green = bcdiv($green, self::MAX_RGB, self::$bcscale);
$this->blue = bcdiv($blue, self::MAX_RGB, self::$bcscale);
// Store some helpful points of interest.
$this->M = max($this->red, $this->green, $this->blue);
$this->m = min($this->red, $this->green, $this->blue);
$this->chroma = bcsub($this->M, $this->m, self::$bcscale);
$this->rgb = $this;
if (isset($original)) {
$this->hsl = $original->hsl;
$this->hsb = $original->hsb;
}
}
示例15: _validateEntries
private function _validateEntries($valueArr)
{
$validUid = true;
$validPage = true;
$validName = true;
$validState = true;
$minNumericVal = $this->_uiConfig["card"]["minNumericLength"];
$maxNumericVal = $this->_uiConfig["card"]["maxNumericLength"];
$minStrVal = $this->_uiConfig["card"]["minStringLength"];
$maxStrVal = $this->_uiConfig["card"]["maxStringLength"];
$validateNumber = v::numeric()->noWhitespace()->length($minNumericVal, $maxNumericVal);
$validateString = v::string()->noWhitespace()->length($minStrVal, $maxStrVal);
if (array_key_exists(":UID", $valueArr) && $valueArr[":UID"] !== "%") {
$validUid = $validateNumber->validate($valueArr[":UID"]);
}
if (!$validUid) {
throw new \InvalidArgumentException('Invalid UID', \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
}
if (array_key_exists(":PAGE", $valueArr) && $valueArr[":PAGE"] !== "%") {
$validPage = $validateString->validate($valueArr[":PAGE"]);
}
if (!$validPage) {
throw new \InvalidArgumentException('Invalid Page', \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
}
if (array_key_exists(":NAME", $valueArr) && $valueArr[":NAME"] !== "%") {
$validName = $validateString->validate($valueArr[":NAME"]);
}
if (!$validName) {
throw new \InvalidArgumentException('Invalid Name', \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
}
if (array_key_exists(":STATE1", $valueArr) && $valueArr[":STATE1"] !== "%") {
$validState = $validateString->validate($valueArr[":STATE1"]);
} elseif (array_key_exists(":STATE", $valueArr) && $valueArr[":STATE"] !== "%") {
$validState = $validateString->validate($valueArr[":STATE"]);
}
if (!$validState) {
throw new \InvalidArgumentException('Invalid State', \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
}
return true;
}