Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Commits on Feb 19, 2013
@harikt harikt Add all and any, and useFieldMessage 3b3c70e
Commits on Mar 19, 2013
@pmjones pmjones Merge pull request #22 from harikt/doc-update
Add all and any, and useFieldMessage
a1d9974
Showing with 71 additions and 1 deletion.
  1. +71 −1 README.md
View
72 README.md
@@ -166,7 +166,7 @@ Available Rules
- `alpha`: Validate the value as alphabetic only. Sanitize to leave only
alphabetic characters. Usage:
-
+
$filter->addSoftRule('field', $filter::IS, 'alpha');
- `between`: Validate the value as being within or equal to a minimum and
@@ -322,6 +322,76 @@ not found returns false. The value cannot be sanitized. Usage:
$filter->addSoftRule('field', $filter::IS, 'word');
+- `any`: Validate the value passes at-least one of the rules. These rules
+are the ones added in rule locator.
+
+ $filter->addSoftRule('field', $filter::IS, 'any', [
+ ['alnum'],
+ ['email'],
+ // more rules
+ ]
+ );
+
+- `all`: Validate the value against a set of rules. These rules
+are should be added in rule locator. You will not get seprate error
+messages for which all rules it failed.
+
+ $filter->addSoftRule('field', $filter::IS, 'all', [
+ // rules
+ ]
+ );
+
+Custom Messages
+===============
+
+By default when a rule fails, the messages you will be getting are from the
+`intl/en_US.php`. But you can also provide a single custom message for
+all the failures.
+
+```php
+$filter->useFieldMessage('field', 'Custom Message');
+```
+
+Example:
+
+```php
+$filter->addSoftRule('username', $filter::IS, 'alnum');
+$filter->addSoftRule('username', $filter::IS, 'strlenBetween', 6, 12);
+$data = (object) [
+ 'username' => ' sds',
+];
+
+$filter->useFieldMessage('username', 'User name already exists');
+// filter the object and see if there were failures
+$success = $filter->values($data);
+if (! $success) {
+ $messages = $filter->getMessages();
+ var_export($messages);
+}
+```
+
+As you have used `useFieldMessage` you will see
+
+```php
+array (
+ 'username' =>
+ array (
+ 0 => 'User name already exists',
+ ),
+)
+```
+
+instead of
+
+```php
+array (
+ 'username' =>
+ array (
+ 0 => 'Please use only alphanumeric characters.',
+ 1 => 'Please use between 6 and 12 characters.',
+ ),
+)
+```
Applying Rules to Individual Values
===================================

No commit comments for this range

Something went wrong with that request. Please try again.