Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve email validation regex in Login and SignUp screens #1107

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/helpers/validationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ const validateCountry = (country: string): boolean => {
return !!COUNTRIES.find((c) => c.country === country);
};

export { validateCountryCode, validateCountry };
const emailRegex = /^([\w.+-]+)@([\w-]+\.)+([\w]{2,})$/gm;

export { validateCountryCode, validateCountry, emailRegex };
3 changes: 2 additions & 1 deletion src/screens/auth/LoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
import Logger from '../../logger';
import { SnackbarProps } from '../../components/Snackbar';
import { emailRegex } from '../../helpers/validationUtils';

const LOG = new Logger('LoginForm');

Expand Down Expand Up @@ -72,7 +73,7 @@ const LoginScreen: React.FC = () => {
}

// Ensure email is valid
if (!email.match(/^(\w+|\d+)@(\w+|\d+)\.(\w+|\d+)/gm)) {
if (!email.match(emailRegex)) {
showError('Must provide valid email');
if (!email) setEmailError(true);
setLoading(false);
Expand Down
4 changes: 2 additions & 2 deletions src/screens/auth/SignUpScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useMemo } from 'react';
import { Button, Snackbar, TextInput } from '../../components';
import { SUPABASE } from '../../supabase/supabaseClient';
import { COUNTRIES, validateCountry } from '../../helpers';
import { COUNTRIES, emailRegex, validateCountry } from '../../helpers';
import { useSessionContext } from '../../hooks';
import { Link, Navigate } from 'react-router';
import InputAdornment from '@mui/material/InputAdornment';
Expand Down Expand Up @@ -103,7 +103,7 @@ const SignUpScreen: React.FC = () => {
}

// Ensure email is valid
if (!email.match(/^(\w+|\d+)@(\w+|\d+)\.(\w+|\d+)/gm)) {
if (!email.match(emailRegex)) {
showError('Must provide valid email');
if (!email) setEmailError(true);
setLoading(false);
Expand Down
Loading