Skip to content

Commit

Permalink
fix: update email validator regex
Browse files Browse the repository at this point in the history
refs: CO-1638
  • Loading branch information
nubsthead authored Nov 28, 2024
1 parent 3ab2b45 commit 114ad32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/settings/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,10 @@ export const differenceObject = (object, base) => {
return changes(object, base);
};

export const validEmailRegex = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;

export const validEmail = (email) => !!validEmailRegex.test(email);
export function isValidEmail(email) {
// eslint-disable-next-line max-len, prettier/prettier, no-useless-escape
const validEmailRegex = /^(?!\.)[\p{L}\p{N}.+_\-]+@[\p{L}\p{N}.+-]+\.[\p{L}\p{N}]{2,}$/u;
return validEmailRegex.test(String(email).toLowerCase());
}

export const findLabel = (list, value) => find(list, (item) => item.value === value)?.label;
4 changes: 2 additions & 2 deletions src/settings/settings-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { editSettings, SettingsHeader, t } from '@zextras/carbonio-shell-ui';
import { map, filter, isEqual, uniqBy } from 'lodash';

import AppleICalSettings from './apple-ical-settings';
import { differenceObject, validEmail } from './components/utils';
import { differenceObject, isValidEmail } from './components/utils';
import CreateAppSettings from './creating-app-settings-view';
import CustomScheduleModal from './custom-schedule-modal';
import GeneralSettingView from './general-settings-view';
Expand Down Expand Up @@ -254,7 +254,7 @@ export default function CalendarSettingsView() {

const saveChanges = useCallback(() => {
if (settingsToUpdate.zimbraPrefCalendarForwardInvitesTo) {
if (!validEmail(settingsToUpdate.zimbraPrefCalendarForwardInvitesTo)) {
if (!isValidEmail(settingsToUpdate.zimbraPrefCalendarForwardInvitesTo)) {
setisEmailNotValid(!isEmailNotValid);
return;
}
Expand Down

0 comments on commit 114ad32

Please sign in to comment.