use once_cell::sync::Lazy;
use regex::Regex;
static NAME_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^(?i)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$")
.expect("Failed to init regexp")
});
pub struct Name;
impl Name {
pub fn validate(domain: &str) -> bool {
domain.len() <= 253 && NAME_REGEX.is_match(domain)
}
pub fn message() -> String {
"Invalid \"domain\". Must be a valid DNS name (e.g. example.com).".into()
}
}