Files
notesnook/apps/mobile/app/services/validation.js

57 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
2023-01-16 13:44:52 +05:00
Copyright (C) 2023 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
2024-07-27 10:19:43 +05:00
import { strings } from "@notesnook/intl";
import isEmail from "validator/lib/isEmail";
2020-01-26 20:45:21 +05:00
export function validateEmail(email) {
if (email && email.length > 0) {
2022-01-22 12:57:05 +05:00
return isEmail(email);
2020-01-26 20:45:21 +05:00
} else {
return false;
}
}
2020-12-30 22:32:43 +05:00
export const ERRORS_LIST = {
2024-07-27 10:19:43 +05:00
SHORT_PASS: strings.passTooShort()
2020-12-30 22:32:43 +05:00
};
2020-01-26 20:45:21 +05:00
export function validatePass(password) {
2020-12-30 22:32:43 +05:00
let errors = {
2022-08-29 16:19:17 +05:00
SHORT_PASS: false
2020-12-30 22:32:43 +05:00
};
2023-06-07 21:00:13 +05:00
if (password?.length < 8) {
2022-08-29 16:19:17 +05:00
errors.SHORT_PASS = true;
2023-06-07 21:00:13 +05:00
} else {
2020-12-30 22:32:43 +05:00
errors.SHORT_PASS = false;
}
2023-06-07 21:00:13 +05:00
2020-12-30 22:32:43 +05:00
return errors;
2020-01-26 20:45:21 +05:00
}
export function validateUsername(username) {
2020-09-09 16:04:26 +05:00
let regex = /^[a-z0-9_-]{3,200}$/gim;
2020-01-26 20:45:21 +05:00
if (username && username.length > 0) {
return regex.test(username);
} else {
return false;
}
}