GithubHelp home page GithubHelp logo

respect / validation Goto Github PK

View Code? Open in Web Editor NEW
5.7K 200.0 773.0 7.56 MB

The most awesome validation engine ever created for PHP

Home Page: https://respect-validation.readthedocs.io

License: MIT License

PHP 99.30% Shell 0.70%
php validation validation-engine fluent-interface validator standalone components

validation's Introduction

validation's People

Contributors

alganet avatar augustohp avatar batusa avatar caferrari avatar danielalt avatar danilobenevides avatar davidepastore avatar dcorrea777 avatar dependabot[bot] avatar edsonlimadev avatar fefas avatar gabrielrcouto avatar henriquemoody avatar jaysonsantos avatar jeanpimentel avatar kinncj avatar kleberhs007 avatar lcobucci avatar nickl- avatar paulkarikari avatar pauloelr avatar rafael-bp avatar reeywhaar avatar regdos avatar rogeriopradoj avatar romeoz avatar sunchayn avatar therespectpanda avatar wesleyvicthor avatar williamespindola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

validation's Issues

Symfony 2.1 bundle

Hey guys.

I'm aware of this Symfony bundle for Respect Validation, but the project seems kind of abandoned.

Is there any other alternatives for Symfony 2.1?

Can/should I start working on that?

Consistency fix: Rename plural rules to singular

An easy task to get you started on the route to becoming a bonafide Respect . Don't fear you are never on your own, you will get all the support you need from the team. Just post to this issue stating your intention to complete this task and its all yours.

Task:
Renaming the plural named rules to their singular forms instead ie. digits, consonants and vowels to digit, constant, vowel etc

Tip: Use $ git mv for renaming files and try and do incremental commits focused around a single change. Use git diff to ensure you are only committing the changes which can be explained in a single line as commit description. Avoid whitespace fixes in your commits or combine them in one single commit.

Have fun!

Not() not working?

The following example from README.md doesn't work

v::not(v::int())->validate(10);

throws out

Notice: Undefined variable: this in library/Respect/Validation/Rules/AbstractRule.php on line 27
Catchable fatal error: Argument 1 passed to Respect\Validation\Rules\Not::__construct() must implement interface Respect\Validation\Validatable, null given, called in library/Respect/Validation/Rules/AbstractRule.php on line 27 and defined in library/Respect/Validation/Rules/Not.php on line 13

but the following works

$test = new Respect\Validation\Rules\Not(v::int());
$ret = $test->validate(10);

I18n

Is there any plan to this?
How could I translate errors?

v::email()->assert('invalid@'); 
# "invalid@" must be valid email.

to

v::email()->assert('invalid@'); 
# "invalid@" deve ser um email válido.

findMessages() broken

As reported by @ed100 in #84

I tried some validations and worked fine.

then I tried to do error messages:

try {
$usernameValidator->assert('really messed up screen#name');
} catch(\InvalidArgumentException $e) {
var_dump($e->findMessages('alnum', 'length', 'noWhitespace'));
}

That give an error:

Catchable fatal error: Argument 1 passed to
Respect\Validation\Exceptions\AbstractNestedException::findMessages()
must be of the type array, string given, called in
/usr/websites/www/validationpage.html on line 14 and defined in
/usr/local/share/pear/Respect/Validation/Exceptions/AbstractNestedException.php
on line 22

also tried on a different try than above:

$errors = $e->findMessages(
'alnum' => '{{name}} must contain only letters and digits',
'length' => '{{name}} must not have more than 15 chars',
'noWhitespace' => '{{name}} cannot contain spaces'
);

and got error:
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in
/usr/websites/www/validationpage.html on line 11

Password confirmation

Is there a way to validate a password confirmation. I.e. validate that one field matches another?

Data Filtering - Filter Functions

There is a whole world of untapped goodness still in Data Filtering

If we want to sugar and spice it with panda goodness while still staying true to the PHP way I am not too sure that we can make this fit into v-double-colon without raping it, ides?

What I am thinking, to also flatten the learning curve both ways, is a new Respect\Validation\Filter along the familiar lines of:

filter::boolean(FILTER_NULL_ON_FAILURE)->var($value);

/** several variations can be supported **/
filter::validate_url(array(
   'options' => array('default'=>'http://example.com'), 
   'flags'=> FILTER_FLAG_PATH_REQUIRED 
       & FILTER_FLAG_HOST_REQUIRED 
        | FILTER_FLAG_QUERY_REQUIRED)
)->var($url);

filter::validate_url(
    FILTER_FLAG_PATH_REQUIRED 
    & FILTER_FLAG_HOST_REQUIRED 
    | FILTER_FLAG_QUERY_REQUIRED)
->options(array('default' => 'http://example.com'))
->input_cookie('domain');

filter::validate_url()->flags(
    FILTER_FLAG_PATH_REQUIRED 
    & FILTER_FLAG_HOST_REQUIRED 
    | FILTER_FLAG_QUERY_REQUIRED)
->options('default', 'http://example.com')
->input_server('host');

/** flag is default and **/
filter::validate_url()->flag(FILTER_FLAG_PATH_REQUIRED)
    ->and_flag(FILTER_FLAG_HOST_REQUIRED)
    ->or_flag(FILTER_FLAG_QUERY_REQUIRED)
->default('http://example.com')
->input_server('host');

filter::validate_url()->flag(FILTER_FLAG_PATH_REQUIRED)
    ->flag('and', FILTER_FLAG_HOST_REQUIRED)
    ->flag('or', FILTER_FLAG_QUERY_REQUIRED)
->default('http://example.com')
->input_server('host');

filter::validate_url()->flag(FILTER_FLAG_PATH_REQUIRED)
    ->flag(0&FILTER_FLAG_HOST_REQUIRED)
    ->flag(0|FILTER_FLAG_QUERY_REQUIRED)
->default('http://example.com')
->input_server('host');

filter::validate_url(FILTER_FLAG_PATH_REQUIRED)
    ->and(FILTER_FLAG_HOST_REQUIRED)
    ->or(FILTER_FLAG_QUERY_REQUIRED)
->default('http://example.com')
->input_env('HOSTNAME');

filter::validate_url('flag_path_required')
    ->and('flag_host_required')
    ->or('flag_query_required')
->default('http://example.com')
->var($url)

filter::validate_url()
    ->flag_path_required()
    ->flag_host_required()
    ->or_flag_query_required()
->default('http://example.com')
->var($url);

filter::validate_url()
    ->flag_path_required()
    ->flag_host_required('flag_query_required')
->default('http://example.com')
->var($url);

/** we can even fix some broken things **/
filter::callback(function ($v) { 
    return strtoupper($a ); 
})->var();

/** or the "valid", read broken, way **/ 
filter::callback(array( 'options' => function ($v) { 
    return strtoupper($a ); 
}))->input_get();

@Respect What are you thinking?

"attribute" rule doesnt work with arrays

Contrary to what the README states ("You can validate attributes of objects or keys of arrays and its values too"), validating array attributes is not implemented.

So this

<?php
use Respect\Validation\Validator;
$a = new stdClass();
$a->a = 42;
Validator::create()->attribute('a', Validator::create()->int())->assert($a);

works, whereas this

<?php
use Respect\Validation\Validator;
$a['a'] = 42;
Validator::create()->attribute('a', Validator::create()->int())->assert($a);

does not.

PHP 5.3 strict exception

Strict

{doc_root}/install/install.php(161): Respect\Validation\Rules\AllOf->assert(NULL)
/Library/WebServer/Documents/work-sites/mcs_ibob/core/trunk/libs/Respect/Validation/Rules/AllOf.php(10): Respect\Validation\Rules\AbstractComposite->validateRules(NULL)
/Library/WebServer/Documents/work-sites/mcs_ibob/core/trunk/libs/Respect/Validation/Rules/AbstractComposite.php(76): Respect\Validation\Rules\AbstractRule->assert(NULL)
/Library/WebServer/Documents/work-sites/mcs_ibob/core/trunk/libs/Respect/Validation/Rules/AbstractRule.php(29): Respect\Validation\Rules\AbstractRule->reportError(NULL)
/Library/WebServer/Documents/work-sites/mcs_ibob/core/trunk/libs/Respect/Validation/Rules/AbstractRule.php(48): Respect\Validation\Exceptions\ValidationException->configure('""', Array)
/Library/WebServer/Documents/work-sites/mcs_ibob/core/trunk/libs/Respect/Validation/Exceptions/ValidationException.php(74): Respect\Validation\Exceptions\ValidationException->guessId()
/Library/WebServer/Documents/work-sites/mcs_ibob/core/trunk/libs/Respect/Validation/Exceptions/ValidationException.php(166)
Only variables should be passed by reference

AllOf not found

I installed Respect/Validation today and when I tried to use it on a test page I got the following error:
Fatal error: Class 'Respect\Validation\Rules\AllOf' not found in /usr/local/share/pear/Respect/Validation/Validator.php on line 61

Installed using pear.

Did I do something wrong or how can I fix/make it work?

Thanks

Improve Travis Setup

Our setup isn't working very well. We're using pyrus and our builds are failing 'cause pyrus is Fatal-Erroring =/ Migrate to composer? Pear? Foundation?

Filtering for Rules

This is a major feature that will require a lot of work.

I've added filtering support for the Int Rule to make some tests.

https://github.com/Respect/Validation/blob/develop/library/Respect/Validation/Filterable.php
https://github.com/Respect/Validation/blob/develop/library/Respect/Validation/Rules/AbstractComposite.php
https://github.com/Respect/Validation/blob/develop/library/Respect/Validation/Rules/Int.php

Filtering on rules will allow users to not just validate data, but filter it.

<?php

$myPureInt = v::int()->filter("12 pigs");
var_dump($myPureInt); //int(12)

For this, a lot of discussion may happen on how each current rule will filter data and how future rules will filter data. It is possible also to create filter-only rules that doesn't validate nothing, but filter data.

Filtering and validation must be called in separate steps for now:

<?php

$validator = v::string()->noWhitespace()->digits()->length(1,20);
$notDirtyAnymore = $validation->filter($someDirtyShit);
$isValid = $validation->validate($notDirtyAnymore);

However, it is desirable (yet-no-so-simple-to-do) to have a build in routine that allows filtering and validating to be chained:

<?php
v::int()->filter()->validate($input); //filter before
v::int()->validate()->filter($input); //filter after

I really need some feedback on this.

Selector Rule

This could be a major rule in this project.

We currently implement some validators that can go deep into objects, like the Key, Attribute and Call rules that, respectively, validates values from array keys, object attributes and method/function calls:

<?php
$foo = array(
    'bar' => (object) array('baz' => 'bat')
);
v::key('bar', v::attribute('baz', v::equals('bat')))->validate($foo); //true

But this could be improved with jquery-like selectors for php:

<?php
$foo = array(
    'bar' => (object) array('baz' => 'bat')
);
v::selector('[bar]->baz', v::equals('bat'))->validate($foo);

Using a method call:

<?php
v::selector('->user->getScreenName()', v::alnum('_'))->validate($someObject);

The selector would extend AllOf and build sub-validators internally using key(), attribute() and call(), so no need for new validation messages. Everything is reused.

Selector parsing needs to be fast. Faster than constructing each validator with v:: manually.

Updating Validtor phpDoc with static keyword

Hi!

It would be nice if you update all @method declarations in Validtor phpDoc with static keyword like this:

  • @method static \Respect\Validation\Validator notEmpty()

PhpStorm understands this normally since 3.0.

Otherwise Storm highlights Validator::notEmpty() with message: "Non-static method 'notEmpty' shouldn't be called statically".

Date validation

I think we could have another validations on Date, like 'isToday' and some others you can think.

Just an idea. Tell me what you guys think about that.

Validate strings with latin characters like Ñ

I've used Validation mainly in English, but because of a project I'm doing I have to validate strings in spanish, meaning that the strings may include accents (áéíóúÁÉÍÓÚ), the letter Ñ (both lower and uppercase) and once in a while üÜ.

So my question is: Is there a way to validate this type of strings?

Besides using v::alpha or v::alnum and having to declare every additional chars.

v::alnum('áéíóúÁÉÍÓÚñÑ')->validate('La piñata de la nación'); 

Alnum validator

The Alnum validator is not respecting the additional chars param.

If I do both:

<?php
use \Respect\Validation\Validator as v;

v::alnum('#')->validate('abc 123 #'); // returns false
(new \Respect\Validation\Rules\Alnum('#'))->validate('abc 123 #'); // returns false

Annotation support

I just wrote an annotation parser (I need it for another thing). I don't like annotation for a very simple reason, performance, since it's not native in PHP, its parsing is performed in the userland and it waste time.

However they are nice :-)

    class Foo {
           /** @Validate(noWhitespace, alphanum, length=[5,32]) */
           public function $username;
    }

It would be nice to add it to Respect\Validation, but it must generate code out of that annotations. Parsing at every request it's nonsense.

Good idea? I have in mind a code generation tool, perhaps we can brainstorm here.

Cheers,

False errors

try {
    $location = v::arr()

        ->key('timezone', v::string()->length(99, 100), false)
            ->setName('timezone')

        ->key('state', v::string(), false)
            ->setName('state')

        ->key('city', v::string(), false)
            ->setName('city');

    $location->assert($testData);

} catch (\Exception $e) {
   var_dump($e->findMessages('timezone', 'state', 'city'));
}

if

$testData = array('timezone' => 'fail', 'city' => 'ok');

or

$testData = array('timezone' => 'fail');

Result:

array(3) {
  ["timezone"]=>
  string(38) "Key timezone must be valid on timezone"
  ["state"]=>
  string(0) ""
  ["city"]=>
  string(41) "These {{failed}} rules must pass for city"
}

(always the last)
But if

$testData = array('city' => 'ok');

no throw exception

PHPUnit segmentation fault error

Hey guys.

When I try to run the tests, the output that I get is the following:

phpunit .
PHPUnit 3.7.6 by Sebastian Bergmann.

Configuration read from /Users/drgomesp/Sites/validation/tests/phpunit.xml

...............................................................  63 / 767 (  8%)
............................................................... 126 / 767 ( 16%)
............................................................... 189 / 767 ( 24%)
............................................................... 252 / 767 ( 32%)
............................................................... 315 / 767 ( 41%)
............................................................... 378 / 767 ( 49%)
............................................................... 441 / 767 ( 57%)
............................................................... 504 / 767 ( 65%)
............................................................... 567 / 767 ( 73%)
............................................................... 630 / 767 ( 82%)
............................................................... 693 / 767 ( 90%)
........................................................SSSSSSS 756 / 767 ( 98%)
S....[1]    8217 segmentation fault  phpunit .

I know this problem is not related to PHPUnit.

Have you guys had this problem before as well?

My environment is:

PHP 5.4.7 (cli) (built: Oct 12 2012 09:43:34)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

New way to tell validators which messages they should use.

Idea I had last night:

v::tell(array(
    'Username must contain only letters and numbers' 
        => v::attribute('username', v::string()->alnum()->notEmpty()),
    'Age must be valid' 
        => v::attribute('birthdate', v::date()->minimumAge(18)),
));

This will generate a flat $e->findMessages(). Calling findMessages() with empty string on old-fashioned validators will bring the top-level validators main messages from them, so it's a micro-refactoring still BC-compatible. Finding messages using selector names like we did before will be possible as well.

Respect\Validation have always been concerned of keeping the validation from the message generation decoupled, but we never tried to provide a nice façade for them to couple when needed, and that it's the source of most of our issues. I believe we can increase the usage of ->assert() and it's messages, which is something Validation users rarely use.`

Completeness: ensure all ctype methods have been implemented.

An easy task to get you started on the route to becoming a bonafide Respect . Don't fear you are never on your own, you will get all the support you need from the team. Just post to this issue stating your intention to complete this task and its all yours.

Task:
Ensure that we have implemented all the ctype functions as additional rules i.e. punct, lower, upper, cntrl etc.

Extra credit:
If you are up for the challenge and earn extra credit, there may be existing rules reinventing the wheel or i.o.w. Existing ctype functions should be used instead of custom regex or similar implementations. If we have reinvented the wheel you can help by removing the new inventions in favour of using the php function for the specific rules instead.

Tip: Try and do small incremental commits focused around a single change. This simplifies the review process. Use git diff to ensure you are only committing the changes which can be explained in a single line, as commit description. Avoid whitespace fixes in your commits or combine them all into one single commit.

Have fun!

Dynamic chaining

Is there any way to chain the validation methods dynamically? My implementation will build validation rules on the fly, so there's no real way to know how to execution the rule until it's built.

Full multi-byte support

Currently some validation rules already implement multi-byte support, but this is a behavior expected for all validators. This means that validating text data using raw strlen(), strpos() or something like that is not recommended. We should use the mb_strlen() or mb_strpos() when they're available. Also, iconv_ functions could also be used.

Conditional validator When

A conditional validator has already been requested by some of our users but currently we don't have an implementation. Usage could be as following:

<?php

use Respect\Validation\Validator as v;

$gravityValidator = v::when(v::int(), v::equals(10))->when(v::float(), v::equals(9.8));
$gravityValidator->validate(10); //true
$gravityValidator->validate(9.8); //true
$gravityValidator->validate('everything else'); //false

In the sample above, a simple condition is created to express a validation that depends on the type of the data. The validator API is simple:

When(**if**, **then**[, **else**]);

If the if validator evaluates true, the then validator is used. If the if validator evaluates false and there is a else validator, it is used.

What do you think?

Request for custom exception messages

Hi, it would be cool if you could make custom exception messages like this

v::callback(function(){}, 'Your thing is not valid');

There seem to be no interface to the defaultTemplates or similar - maybe I missed it.

Cool lib, btw ;)

Completeness: Ensure all is_* functions are implemented

An easy task to get you started on the route to becoming a bonafide Respect . Don't fear you are never on your own, you will get all the support you need from the team. Just post to this issue stating your intention to complete this task and its all yours.

Task:
Ensure that we have implemented all the is_* Variable handling Functions the unwritten convention thus far is just to drop the is_ part ie. is_numeric() becomes v::numeric() when naming the new rules.

Tip: Try and do small incremental commits focused around a single change. This simplifies the review process. Use git diff to ensure you are only committing the changes which can be explained in a single line, as commit description. Avoid whitespace fixes in your commits or combine them all into one single commit.

  • is_a
  • is_array
  • is_bool
  • is_callable
  • is_dir
  • is_double, is_float, is_real
  • is_executable
  • is_file
  • is_finite
  • is_infinite
  • is_int, is_integer, is_long
  • is_link
  • is_nan
  • is_null
  • is_numeric
  • is_object
  • is_readable
  • is_resource
  • is_scalar
  • is_string
  • is_subclass_of
  • is_uploaded_file
  • is_writable, is_writeable
  • isset

Have fun!

IP range validation

I need to do a network address range's validation (IPv4) in a project, so I thought that it may be a nice feature to Respect\Validation.

My first idea was to use the ip and between, something like this:

v::ip()->between(ip2long('192.168.0.0'), ip2long('192.168.0.255'))
       ->validate(ip2long('192.168.0.80'));

But it gets a little bit verbose. I believe that would be awesome to allow the following validations using a easy interface (http://www.aprelium.com/data/doc/2/abyssws-win-doc-html/ipformat.html):

  1. Using wildcards (192.168.0.*)
  2. Using ranges (192.168.0.0-192.168.0.255)
  3. Using CIDR (192.168.0.0/21)

The first thought that we can add a new constructor parameter, like this:

v::ip(null, '192.168.0.*')->validate(ip2long('192.168.0.80'));

But I believe that doesn't follow the project standards and we still have to use the ip2long() on validate().

What's your sugestion about this?

Leap Date Validation

PHP's build in DateTime converts leap dates automatically. For example, 2001-02-29 automatically casts to 2001-03-01, which is, in some cases, not desired.

The proposed validator adds a new parameter to the date validation.

Date(format, convertLeapDates)

Behavior: v::date(null, true)->validate('2001-02-29'); should return false.

Plugin Architecture

At this point, I believe some kind of plugin architecture is needed. Before thinking in any implementation details, i'd like to discuss the use cases for this. Some of them are already valid for our developers:

-Localized validators like CPF (kinda social security number here in Brasil) that @jairhenrique did.
-Large validator groups for specific tasks like the Twitter group of validators that @cloudson is working on.

More use cases would be awesome to gather info for implementation proposals.

Thank you all!

Array in array

$testData = array('city' => 'no array');
try {
    $location = v::arr()

        ->key('city', v::arr()->key('test', v::string()))
            ->setName('city');

    $location->assert($testData);

} catch (\Exception $e) {

}

Result:

Warning:  array_key_exists() expects parameter 2 to be array, string given in library\Respect\Validation\Rules\Key.php on line 27

Security & Rule Improvements

Welcome to @ericktedeschi! We'll help us with tips security and strictly rule validation. We already discussed some of improvements we're planning to do:

  • Better credit card validation
  • Better domain validation

Wiki - Documentação

Estava conversando com o @alganet sobre documentação, e chegamos a conclusão de que seria melhor manter um issue para discutirmos abertamente as melhores formas para a documentação do projeto.

A documentação será feita na wiki do projeto e acho interessante seguir algumas coisas:

  • Para títulos das páginas das regras de validação (rules) manter o padrão: Rules/RuleName ex: Rules/Numeric
  • Para páginas que não estiverem em inglês, adicionar a abreviação do idioma no título: Rules/RuleName - pt ex: Rules/Numeric - pt
  • No Corpo da página, fazer uma descrição simples e objetiva, adicionar exemplo(s), e descrever as funções existentes.

Dumb validators for mocking and testing purposes.

There's a need for simple validators in our tests and perhaps in other users tests. Two proposed rules are: AlwaysValid e AlwaysInvalid rule. They just return true or false.

Also, as a part of this issue, a nice improvement in our tests could be finding every case in which we're using Callback Rule to mock AlwaysValid and AlwaysInvalid and replace with the proper dumb validators.

Warning preg_match for v::regex

I get an error:
Warning: preg_match() [function.preg-match]: Unknown modifier '^' in ...Respect\Validation\Rules\Regex.php on line 17

trying to use an email regex for validation '^[^0-9][A-z0-9_]+([.][A-z0-9_]+)[@][A-z0-9]+([.][A-z0-9_]+)_[.][A-z]{2,4}$' and it shows this error

Why are validation shown against value rather than field name?

Currently If I try to validate $_POST['username'] I get the value in the validation message rather than the name username?

try {
    v::alnum()
        ->noWhitespace()
        ->length(4,22)
        ->check($_POST['username']);
} catch (\InvalidArgumentException $e) {
    var_dump($e->getMainMessage());
}

result

"" must not contain whitespace

what I was expecting

"username" must not contain whitespace

Hostname/Domain validator

This is a major validator with a lot of work to do that could be splitted in several steps:

Syntax could be v::hostname() and v::internationalHostname().

Float Rule bug

A regra float retorna true independente se o numero é de ponto flutuante ou não:

<?php
use Respect\Validation\Validator as v;

        var_dump(v::float()->validate(1.234)); //bool(true)
        var_dump(v::float()->validate(23)); //bool(true)

Fiz alguns teste com a função filter_var() e só retornou false quando testei com uma string:

<?php
var_dump(filter_var('some string' , FILTER_VALIDATE_FLOAT)); //bool(false)
var_dump(filter_var(10 , FILTER_VALIDATE_FLOAT)); //float(10)

Não seria melhor usar is_float()? Modifiquei aqui e funcionou.

Create `age` validator (Deprecates `minimumAge`)

This resumes the discussion happened below until @caferrari comment:

  1. Create an age validation rule: v::age($min, $max=null).
  2. Deprecate (remove) mininumAge validation rule in favor of the age rule.

Original message (for historical purposes):

There is a minimumAge but no maximumAge.
Any reason, or just missed?

Manage multiple validation Rules namespaces

It is pretty easy to write new rules, this could be exposed to another namespaces other than Respect\Validation\Rules.

We can always rely on class_alias to do this, but having something more user friendly wouldn't be nicer?

setTemplate doesn't work?

I made a test similar to the one in here:
3ed3114#diff-5

function test_set_template() {
  try {
    Validator::callback('is_int')->setTemplate('{{name}} is not tasty')->assert('something');
  } catch (\Exception $e) {
    $this->assertEquals('"something" is not tasty', $e->getMainMessage());
  }   
}

But it fails the test. It seems it's using the default one.

Maybe I'm not using it correctly?

JS Wrapper client side validation

Retweeted this:
@phprespect: JS wrapper like PHP-Validation/examples/jquery.php at master · Dachande663/PHP-Validation · GitHub http://flip.it/JCPdo

There is always the debate to validate on the back end or on the client or both. We will gain huge Respect if we have the same solution for both.

Perhaps some v::render() or v::export() to get the same from all the rules, a js flavoured counterpart.

Something to chew on...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.