Super simple way to validte inputs in rust
This crate is early in development and mainly a proof of concept but if you wish to try it out you can add the following line to your Cargo.toml
file
simple-validate = { git = "https://github.com/cleggacus/simple-validate" }
use simple_validate::validate::Validate;
fn main() {
let password_validator = Validate::string()
.regex_message(
r"(?=.*[a-z])",
"must contain a lowercase character"
)
.regex_message(
r"(?=.*[A-Z])",
"must contain an uppercase character"
)
.regex_message(
r#"(?=.*[0-9\!@#$%^&*()\[\]{}\-_+=~`|:;"'<>,./?])"#,
"must contain number or special character"
)
.min(8)
.max(128);
let email_validator = Validate::string().email();
let email = "[email protected]";
let password = "pass";
println!("{:?}", email_validator.parse(email));
println!("{:#?}", password_validator.parse(password));
}
Ok("[email protected]")
Err(
[
"must contain an uppercase character",
"must contain number or special character",
"min string length is 8",
],
)