Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ validation functions and types.
## Validators
The crate comes with some built-in validators and you can have several validators for a given field.

### email
### email (optional)
Tests whether the String is a valid email according to the HTML5 regex, which means it will mark
some esoteric emails as invalid that won't be valid in a `email` input as well.
This validator doesn't take any arguments: `#[validate(email)]`.

### url
### url (optional)
Tests whether the String is a valid URL.
This validator doesn't take any arguments: `#[validate(url)]`;

Expand Down Expand Up @@ -244,7 +244,7 @@ Examples:
#[validate(does_not_contain(pattern = "gmail"))]
```

### regex
### regex (optional)
Tests whether the string matches the regex given. `regex` takes
1 string argument: the path to a static Regex instance.

Expand Down Expand Up @@ -402,5 +402,10 @@ For example, the following attributes all work:
```

## Features
By default, the `email`, `url` and `regex` features are enabled to provide compatibility with versions < 0.21.0.s

`derive` - This allows for the use of the derive macro.
`derive_nightly_features` - This imports both derive as well as proc-macro-error2 nightly features. This allows proc-macro-error2 to emit extra nightly warnings.
`email` - Allows for email validation, pulls in idna and turns on `regex` feature flag.
`url` - Allows for url validation, pulls in url optional dependency.
`regex` - Allows for regex validation, pulling in regex optional dependency.
12 changes: 8 additions & 4 deletions validator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "validator"
version = "0.20.0"
version = "0.21.0"
authors = ["Vincent Prouillet <hello@vincentprouillet.com"]
license = "MIT"
description = "Common validation functions (email, url, length, ...) and trait - to be used with `validator_derive`"
Expand All @@ -12,9 +12,9 @@ readme = "../README.md"
rust-version = { workspace = true }

[dependencies]
url = "2"
regex = { version = "1", default-features = false, features = ["std"] }
idna = "1"
url = { version = "2", optional = true }
regex = { version = "1", default-features = false, features = ["std"], optional = true }
idna = { version = "1", optional = true }
serde = "1"
serde_derive = "1"
serde_json = "1"
Expand All @@ -23,6 +23,10 @@ card-validate = { version = "2.3", optional = true }
indexmap = { version = "2.0.0", features = ["serde"], optional = true }

[features]
default = ["regex", "url", "email"]
card = ["card-validate"]
derive = ["validator_derive"]
derive_nightly_features = ["derive", "validator_derive/nightly_features"]
regex = ["dep:regex"]
url = ["dep:url"]
email = ["dep:idna", "regex"]
3 changes: 3 additions & 0 deletions validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ mod validation;
pub use validation::cards::ValidateCreditCard;
pub use validation::contains::ValidateContains;
pub use validation::does_not_contain::ValidateDoesNotContain;
#[cfg(feature = "email")]
pub use validation::email::ValidateEmail;
pub use validation::ip::ValidateIp;
pub use validation::length::ValidateLength;
pub use validation::must_match::validate_must_match;
pub use validation::non_control_character::ValidateNonControlCharacter;
pub use validation::range::ValidateRange;
#[cfg(feature = "regex")]
pub use validation::regex::{AsRegex, ValidateRegex};
pub use validation::required::ValidateRequired;
#[cfg(feature = "url")]
pub use validation::urls::ValidateUrl;

pub use traits::{Validate, ValidateArgs};
Expand Down
3 changes: 3 additions & 0 deletions validator/src/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
pub mod cards;
pub mod contains;
pub mod does_not_contain;
#[cfg(feature = "email")]
pub mod email;
pub mod ip;
pub mod length;
pub mod must_match;
// pub mod nested;
pub mod non_control_character;
pub mod range;
#[cfg(feature = "regex")]
pub mod regex;
pub mod required;
#[cfg(feature = "url")]
pub mod urls;
2 changes: 1 addition & 1 deletion validator_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "validator_derive"
version = "0.20.0"
version = "0.21.0"
authors = ["Vincent Prouillet <hello@vincentprouillet.com"]
license = "MIT"
description = "Macros 1.1 implementation of #[derive(Validate)]"
Expand Down