Panic validator is adobted for simple lovely and easy like common validation in php
There are no hardcoded for simply usage, no weight and pretty useful
composer require "moviet/panic-validator"
- Simply Validation
- Custom Warning
- Custom Verification
- Simple Filtering
- Modify Pattern
- Validate Password
- Sanitize Html
- ❖ Plus Bonus ❖
You can validate with fast direct resolve example
require__DIR__ . '/vendor/autoload.php'; useMoviet\Validator\Panic; useMoviet\Validator\Ival; $panic = newPanic; $nom = 'Smile'; $getnom = $panic->case($nom) ->rule(':alpha') ->get(); // var_dump : Smile
The above will return value, if doesn't match will return false
Or maybe you enjoy quietly with something like this
$data = $panic->match(':doc','mydocument.xls'); // Output : mydocument.xls
The above will return value, if doesn't match will return false
Validate using your own message
$request = $_POST['String']; $post = $panic->case($request) ->rule(':alNumSpace') ->throw(['Do not burn your finger, invalid !!']);
Validate using limit and custom language
$somePost = $panic->case($_POST['String']) ->lang('En') // Optional ->min(3) ->max(100) ->rule(':alphaSpace') ->throw(['Please follow wakanda alphabets']);
Validate using empty case
$anyPost = $panic->case(/*..Empty..*/) ->rule(':alpha') ->throw(['~ Gunakan angka atau spasi']); // Output : 'Please Fill Out The Form'
Notes :
You can't validate an empty value, by default the field does not allow empty chunks
You can validate for example html form like simply below
$validUser = $panic->case($_POST['username']) ->rule(':email') ->throw(['Your username may error !!']); $validPass = $panic->case($_POST['password']) ->auth(8) ->throw(['Password minimum 8 characters']); $tokenLog = $panic->case($_POST['csrf']) ->rule(':alphaNum') ->get(); $data = [$validUser, $validPass, $tokenLog]; if ($panic->confirm($data) !== false) { // $_POST['username']// $_POST['password']// ... }
Render on your own template html form example
<formmethod="POST" action="login.php" name="login"><table><tbody><tr><td><?php if (!$validUser) ?><divclass="title_form">Username * <labelfor='username' class='error'><?= $validUser; ?></label></div><inputtype="text" placeholder="Enter username" name="username" class="form_login" value="" required></td></tr><tr><td><?php if (!$validPass) ?><divclass="title_form">Password * <labelfor='password' class='error'><?= $validPass; ?></label></div><inputtype="text" placeholder="Enter password" name="password" class="form_login" value="" required></td></tr></tbody></table></form>
If the above doesn't look so nice, you can trust with new endorse
$product = $panic->case($_GET['product']) ->rule(':alNumSpace') ->throw(['Do not only look, Please bo bo boy !!']); $tokenId = $panic->case($_GET['token_id']) ->rule(':int') ->throw(['Your token of course, invalid !!']); $validate = [$product, $tokenId]; $entry = $panic->trust($_GET, $validate); // to retrieve data, please use arrayif ($entry !== false) $entry[0] // Equivalent $product$entry[1] // Equivalent $tokenId Next Next...
We use native filter functions look like below
$url = 'https://github.com/moviet/panic-validator'; $data = $panic->filter(':url', $url); // Output : https://github.com/moviet/panic-validator
You can modify with modify like modify your own rules
$myrule = $panic->case('My name is yoyo') ->min(2) ->max(20) ->modify('/^[a-zA-Z 0-9]*$/') ->throw(['What the hell something wrong ??']); // Return Boolen
You may want to draft and match for non messenger
$string = 'Thanks you'; $data = $panic->draft('/^[a-zA-Z@0-9_1-`-02-^"?>/+\//./]*$/', $string); // Output : Thanks you$string = 'Thanks Match'; $data = $panic->match(':message', $string); // Output : Thanks Match
We put a simply for native password hash validation
$data = $panic->verify($_POST['password'], 'DataPassword') ->warn('Do not type password, please use Abcde !!'); if ($panic->catch($data)) { // $_POST['password'] } // Print $data => Do not type password, please use Abcde !!
You can sanitize with our little pony for simply safe html as one packet
$stringHtml = '<script> If this is XSS </script>'; $filterHtml = $panic->htmlSafe($stringHtml); $html = $panic->htmlRaw($filterHtml); // Output : <script> If this is XSS </script>
Whatever usage a custom clean base64 encode may interesting
$string = 'And thanos will go on'; $encode = $panic->base64($string); // Output : aOAIOAIHJSDH837287ksasjka983jsdhdsfsJHJAdsfd34dfSfb$decode = $panic->pure64($encode); // Output : And thanos will go on
| Attributes | Format |
|---|---|
| :num | 0 - 9 |
| :phone | +081991988xx (plus +) |
| :int | Integer/Number |
| :alpha | Alphabets |
| :alphaNum | Alphabets Number |
| :alphaSpace | Alphabets Plus Spaces |
| :alNumSpace | Alphabets Number Spaces |
| :query | Http Url Query |
| :url | Url Address |
| :image | jpg, jpeg, png, bmp, gif |
| :doc | pdf,xls,doc,rtf,txt,ppt,pptx |
| :address | Normal Address |
| :subject | Email Subject |
| Email Address | |
| :message | Simple Message Characters |
| Attributes | Format |
|---|---|
| :int | Filter Validate Integer |
| :float | Filter Validate Float |
| :url | Filter Validate Url |
| :domain | Filter Validate Domain |
| :ip4 | Filter Validate IP4 |
| :ip6 | Filter Validate IP6 |
| Filter Validate Email |
Moviet/panic-validator is released under the MIT public license.