diff --git a/src/main.rs b/src/main.rs index 49780d4..741c51e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,6 +106,15 @@ fn validate_email(email: &String) -> bool { Regex::new(r"^[a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]+$").unwrap().is_match(email) } +fn validate_guests(guests: &u8) -> bool { + // Check if the default number of guests (255) changed. + if guests < &255 { + true + } else { + false + } +} + fn strip_tld(url: &str) -> Option { // Get the top level domain which is used to determine the language @@ -204,7 +213,7 @@ fn submit_task (host: HostHeader, Some(x) => { // Check input for anything strange or something that does not look like // an email address. - if validate_name(&x.name) && validate_email(&x.email) { + if validate_name(&x.name) && validate_email(&x.email) && validate_guests(&x.guests){ // Create HashMap to use with strfnt let mut vars = HashMap::new(); vars.insert("name".to_string(), &x.name); @@ -255,7 +264,7 @@ fn submit_task (host: HostHeader, &settings); } } else { - result = Err("Validate e-mail or name went wrong.".to_string()); + result = Err("Validate e-mail, name, or number of guests went wrong.".to_string()); } // Send a message to the sender's e-mailaddres to inform about