From a1c3789ec20bc2b7f61665d6529f11f7ee4669ee Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 3 Mar 2022 14:15:45 +0100 Subject: [PATCH] :tada: Add parse email helper function --- common/src/app/common/spec.cljc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/spec.cljc b/common/src/app/common/spec.cljc index 15b0cd1e7..083011b7b 100644 --- a/common/src/app/common/spec.cljc +++ b/common/src/app/common/spec.cljc @@ -161,14 +161,14 @@ (def email-re #"[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+") +(defn parse-email + [s] + (some->> s (re-seq email-re) first)) + (s/def ::email (s/conformer (fn [v] - (if (string? v) - (if-let [matches (re-seq email-re v)] - (first matches) - (do ::s/invalid)) - ::s/invalid)) + (or (parse-email v) ::s/invalid)) str)) (s/def ::set-of-emails