Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please check <a href="http://documentup.com/Respect/Validation" rel="noreferrer">Respect\Validation</a>. It's a library built for that purpouse. It can handle multiple rules very easily and uses exceptions for errors. Here is a quick sample:</p> <pre><code>&lt;?php use Respect\Validation\Validator as v; $usernameValidator = v::alnum()-&gt;noWhitespace()-&gt;length(1,15); $valid = $usernameValidator-&gt;validate("alganet"); //$valid now == true $valid = $usernameValidator-&gt;validate("ácido acético"); //$valid now == false </code></pre> <p>Now using exceptions:</p> <pre><code>try { $usernameValidator-&gt;assert("foo # bar"); } catch (Exception $e) { $errors = $e-&gt;findMessages('alnum', 'noWhitespace', 'length'); } </code></pre> <p>In the sample above, the <code>$errors</code> variable would be something like this:</p> <pre><code>array( "alnum" =&gt; '"foo # bar" must contain only letters and digits', "noWhitespace" =&gt; '"foo # bar" must not contain whitespace', "length" =&gt; null ) </code></pre> <p>I broke two previously declared rules using "foo # bar": It has whitespace and it has a non-alnum char. For every rule that doesn't pass, a message will be returned. Since "length" is OK, the error message is null.</p> <p>The <a href="http://documentup.com/Respect/Validation" rel="noreferrer">documentation</a> includes several more samples including nested, hierarchical rules and better exception handling. Also has a extensive list of samples for all of the 30+ built in validators.</p> <p>Hope that helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload