February 9, 2024 (7mo ago)
"use client";
import { useState } from "react";
function isEmailValid(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
export default function Page() {
const [email, setEmail] = useState("");
const [isValidEmail, setIsValidEmail] = useState(false);
function handleEmailChange(event) {
const newEmail = event.target.value;
setEmail(newEmail);
setIsValidEmail(isEmailValid(newEmail));
}
return (
<form>
<input
type="email"
value={email}
onChange={handleEmailChange}
className={isValidEmail ? "text-green-500" : "text-red-500"}
/>
<button type="submit">Submit</button>
</form>
);
}
function testUsername(u: string) {
return /^[0-9A-Za-z]{6,16}$/.test(u);
}
function testPassword(testcase: string) {
return (
/^(?=.*?[0-9])(?=.*?[A-Za-z]).{8,32}$/.test(testcase) &&
/^(?=.*?[0-9])(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^0-9A-Za-z]).{8,32}$/.test(
testcase
)
);
}