Compare commits

..

No commits in common. "c67c05428bff9f6aa1b144f7c5c2b6ef34ce3612" and "a15813b8fdc82908656bf27eff5765988a5e629c" have entirely different histories.

4 changed files with 16 additions and 33 deletions

View File

@ -18,7 +18,6 @@ import BaseTextInput from "@/components/forms/BaseTextInput";
import PasswordInput from "@/components/forms/PasswordInput";
import PrimaryButton from "@/components/buttons/PrimaryButton";
import FieldLabel from "@/components/forms/FieldLabel";
import { validateEmail } from "@/constants/countries";
import { forgotPassword, resetPassword } from "@/features/auth/api/auth.api";
export default function ForgotPasswordScreen() {
@ -37,9 +36,12 @@ export default function ForgotPasswordScreen() {
const handleRequestOtp = async () => {
setEmailError("");
const cleanEmail = email.trim().toLowerCase();
const emailErr = validateEmail(cleanEmail);
if (emailErr) {
setEmailError(emailErr);
if (!cleanEmail) {
setEmailError("Email is required");
return;
}
if (!/\S+@\S+\.\S+/.test(cleanEmail)) {
setEmailError("Please enter a valid email address");
return;
}

View File

@ -256,24 +256,3 @@ export const updatePhoneDialCode = (
const bounded = nationalDigits.slice(0, newRule.maxLength);
return bounded ? `${newRule.code} ${bounded}` : `${newRule.code} `;
};
/**
* RFC 5322 & RFC 1035 compliant email validation regex.
* Disallows invalid domain characters (e.g. + in domain like +gmail+.com, consecutive dots, leading/trailing hyphens)
* while properly accepting plus-addressing in local-part (e.g. sanskar+sarak@gmail.com).
*/
export const EMAIL_REGEX = /^[a-zA-Z0-9_%+-]+(?:\.[a-zA-Z0-9_%+-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/;
export const validateEmail = (email?: string | null): string | null => {
if (!email || !email.trim()) {
return "Email is required";
}
if (!EMAIL_REGEX.test(email.trim())) {
return "Please enter a valid email address";
}
return null;
};
export const isValidEmail = (email?: string | null): boolean => {
return validateEmail(email) === null;
};

View File

@ -17,7 +17,6 @@ import PasswordInput from "@/components/forms/PasswordInput";
import PrimaryButton from "@/components/buttons/PrimaryButton";
import { AuthColors } from "../constants/colors";
import { validateEmail } from "@/constants/countries";
import { useAuthStore } from "@/store/auth.store";
import { LoginMethod } from "./LoginTabs";
import { login } from "@/features/auth/api/auth.api";
@ -53,9 +52,11 @@ export default function LoginForm({
setPasswordError("");
if (activeTab === "email") {
const emailErr = validateEmail(email);
if (emailErr) {
setEmailError(emailErr);
if (!email.trim()) {
setEmailError("Email is required");
hasError = true;
} else if (!/\S+@\S+\.\S+/.test(email)) {
setEmailError("Please enter a valid email address");
hasError = true;
}
} else {

View File

@ -28,7 +28,6 @@ import {
CountryCode,
DEFAULT_COUNTRY,
validatePhoneNumber,
validateEmail,
} from "@/constants/countries";
import { useAuthStore } from "@/store/auth.store";
import { register } from "@/features/auth/api/auth.api";
@ -93,9 +92,11 @@ export default function SignUpForm() {
hasError = true;
}
const emailErr = validateEmail(email);
if (emailErr) {
setEmailError(emailErr);
if (!email.trim()) {
setEmailError("Email is required");
hasError = true;
} else if (!/\S+@\S+\.\S+/.test(email)) {
setEmailError("Please enter a valid email address");
hasError = true;
}