From 79cd7f7df5b96625c2aa950f41b0e9f4b29b0913 Mon Sep 17 00:00:00 2001 From: Brian Sztamfater Date: Thu, 30 Mar 2023 21:24:59 -0300 Subject: [PATCH] fix: add min 5 characters validation for display names Signed-off-by: Brian Sztamfater --- .../contexts/onboarding/create_profile/view.cljs | 9 ++++++++- translations/en.json | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/status_im2/contexts/onboarding/create_profile/view.cljs b/src/status_im2/contexts/onboarding/create_profile/view.cljs index f8c47ccbca..4055ec4ad2 100644 --- a/src/status_im2/contexts/onboarding/create_profile/view.cljs +++ b/src/status_im2/contexts/onboarding/create_profile/view.cljs @@ -35,6 +35,10 @@ (defn has-common-names [s] (pos? (count (filter #(string/includes? s %) common-names)))) (def special-characters-regex (new js/RegExp #"[^a-zA-Z\d\s-._]" "i")) (defn has-special-characters [s] (re-find special-characters-regex s)) +(def min-length 5) +(defn length-not-valid [s] (< (count (string/trim s)) min-length)) +(def valid-regex (new js/RegExp #"^[\w-\s]{5,24}$" "i")) +(defn valid-name [s] (re-find valid-regex s)) (defn validation-message [s] @@ -47,6 +51,9 @@ (string/ends-with? s ".eth") (i18n/label :t/ending-not-allowed {:ending ".eth"}) (has-common-names s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/common-names)}) (has-emojis s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/emojis)}) + (length-not-valid s) (i18n/label :t/name-must-have-at-least-characters + {:min-chars min-length}) + (not (valid-name s)) (i18n/label :t/name-is-not-valid) :else nil)) (defn button-container @@ -67,7 +74,7 @@ validation-msg (reagent/atom (validation-message @full-name)) on-change-text (fn [s] (reset! validation-msg (validation-message s)) - (reset! full-name s)) + (reset! full-name (string/trim s))) custom-color (reagent/atom (or color c/profile-default-color)) profile-pic (reagent/atom image-path) on-change-profile-pic #(reset! profile-pic %) diff --git a/translations/en.json b/translations/en.json index 6d4b47a4f7..727a215be4 100644 --- a/translations/en.json +++ b/translations/en.json @@ -2054,5 +2054,7 @@ "error-syncing-connection-failed": "Oops! Connection failed. Try again", "camera-permission-denied": "Permission denied", "enable-biometrics": "Enable biometrics", - "use-biometrics": "Use biometrics to fill in your password" + "use-biometrics": "Use biometrics to fill in your password", + "name-must-have-at-least-characters": "Name must have at least {{min-chars}} characters", + "name-is-not-valid": "Name is not valid" }