diff options
| author | Valerian Saliou | 2017-10-09 18:36:03 -0700 |
|---|---|---|
| committer | Valerian Saliou | 2017-11-07 07:59:58 -0500 |
| commit | 304ff212e20cd10e2f4bc99a54385db461a3a27d (patch) | |
| tree | 430f08a7fe7da65d8f152171512e1b9724cf7f07 /README.md | |
| parent | 4d7138e040cd5faaf84448a75b64f3ff0e4673e5 (diff) | |
| download | validator-304ff212e20cd10e2f4bc99a54385db461a3a27d.tar.bz2 | |
Ability to validate an international phone number
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
Derives for the ‘phone’ validator (still unsure about it)
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
Fix review
Merge + Add missing documented ‘credit_cards’ feature
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
Fix
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
Fix
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
Merge
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
‘credit_cards’ feature is no longer needed as per #33
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -6,17 +6,17 @@ Macros 1.1 custom derive to simplify struct validation inspired by [marshmallow] [Django validators](https://docs.djangoproject.com/en/1.10/ref/validators/). It relies on the `proc_macro` feature which is stable since Rust 1.15. -By default all args to a `validate` must be strings if you are using stable. +By default all args to a `validate` must be strings if you are using stable. However, if you are using nightly, you can also activate the `attr_literals` feature to be able to use int, float and boolean as well. A short example: ```rust -#[macro_use] +#[macro_use] extern crate validator_derive; extern crate validator; -#[macro_use] +#[macro_use] extern crate serde_derive; extern crate serde_json; @@ -27,6 +27,8 @@ use validator::{Validate, ValidationError}; struct SignupData { #[validate(email)] mail: String, + #[validate(phone)] + phone: String, #[validate(url)] site: String, #[validate(length(min = "1"), custom = "validate_unique_username")] @@ -151,8 +153,21 @@ Examples: #[validate(regex = "ALLOWED_USERNAMES_RE"))] ``` +### credit\_card +Test whetever the string is a valid credit card number. + +Examples: + +```rust +#[validate(credit_card)] +``` + +### phone +Tests whether the String is a valid phone number (in international format, ie. containing the country indicator like `+14152370800` for an US number — where `4152370800` is the national number equivalent, which is seen as invalid). To use this validator, you must enable the `phone` feature for the `validator` crate. +This validator doesn't take any arguments: `#[validate(phone)]`; + ### custom -Calls one of your function to do a custom validation. +Calls one of your function to do a custom validation. The field will be given as parameter and it should return a `Option<String>` representing the error code, if there was an error. |
