import React, { useState } from 'react'; const LoginPage = () => { const [loginType, setLoginType] = useState('email'); // 'email' or 'phone' const [identifier, setIdentifier] = useState(''); const [password, setPassword] = useState(''); const handleLogin = (e) => { e.preventDefault(); if (!identifier || !password) { alert('Please fill in all fields.'); return; } if (loginType === 'email') { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(identifier)) { alert('Please enter a valid email address.'); return; } } else { // Basic phone number validation (e.g., starts with + and has digits) const phoneRegex = /^\+?[0-9\s-]{8,}$/; if (!phoneRegex.test(identifier)) { alert('Please enter a valid phone number.'); return; } } console.log(`Attempting to log in with ${loginType}: ${identifier}`); // In a real application, you would make an API call here alert(`Login successful with ${loginType}!`); }; return (
Login to access your account.