]> saetta.ns0.it Git - rust/zakform/commitdiff
ValidatorDate: empty date is valid.
authorAndrea Zagli <azagli@libero.it>
Sat, 11 May 2024 08:22:50 +0000 (10:22 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 11 May 2024 08:22:50 +0000 (10:22 +0200)
src/validators.rs

index b06ffae008f382148ceab8c152205ddb4b20a8bf..260643088a33b44bd73a11e0238d38fa2132444a 100644 (file)
@@ -140,7 +140,12 @@ impl TValidator for ValidatorDate {
        }
 
        fn validate(&self, value: &String) -> String {
-               let d = match chrono::NaiveDate::parse_from_str(value, "%d/%m/%Y" ) {
+               let value_ = value.trim();
+               if value_ == "" {
+                       return String::from("");
+               }
+
+               let d = match chrono::NaiveDate::parse_from_str(value_, "%d/%m/%Y" ) {
                        Ok(r) => { r },
                        Err(_) => { return self.get_message(); }
                };