From 41f15fc82ca5d074584e03e0eda87ace2f5f2301 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 17 May 2023 10:30:38 +0200 Subject: [PATCH] no autocomplete on username input, improved regex for username validations --- .../src/components/Inputs/InputUsername.vue | 1 + frontend/src/validation-rules.js | 27 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/Inputs/InputUsername.vue b/frontend/src/components/Inputs/InputUsername.vue index 25a15ee33..e2048a781 100644 --- a/frontend/src/components/Inputs/InputUsername.vue +++ b/frontend/src/components/Inputs/InputUsername.vue @@ -17,6 +17,7 @@ :placeholder="placeholder" type="text" :state="validated ? valid : false" + autocomplete="off" >
diff --git a/frontend/src/validation-rules.js b/frontend/src/validation-rules.js index 53b301676..124ef8528 100644 --- a/frontend/src/validation-rules.js +++ b/frontend/src/validation-rules.js @@ -134,27 +134,24 @@ export const loadAllRules = (i18nCallback, apollo) => { extend('usernameHyphens', { validate(value) { - return !!value.match(/^[a-zA-Z0-9]+(?:[_-][a-zA-Z0-9])*$/) + return !!value.match(/^[a-zA-Z0-9]+(?:[_-][a-zA-Z0-9]+?)*$/) }, message: (_, values) => i18nCallback.t('form.validation.username-hyphens', values), }) extend('usernameUnique', { validate(value) { - if (value.match(/^(?=.{3,20}$)[a-zA-Z0-9]+(?:[_-][a-zA-Z0-9])*$/)) { - return apollo - .query({ - query: checkUsername, - variables: { username: value }, - }) - .then(({ data }) => { - return { - valid: data.checkUsername, - } - }) - } else { - return false - } + if (!value.match(/^(?=.{3,20}$)[a-zA-Z0-9]+(?:[_-][a-zA-Z0-9]+?)*$/)) return true + return apollo + .query({ + query: checkUsername, + variables: { username: value }, + }) + .then(({ data }) => { + return { + valid: data.checkUsername, + } + }) }, message: (_, values) => i18nCallback.t('form.validation.username-unique', values), })