screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [password, setPassword] = useState(""); const [showValidationMessage, setShowValidationMessage] = useState(false); const [validationMessage, setValidationMessage] = useState(""); const [showPassword, setShowPassword] = useState(false); const validatePassword = () => { const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/; if (!password) { setShowValidationMessage(false); return; } if (passwordRegex.test(password)) { setShowValidationMessage(false); } else { setShowValidationMessage(true); setValidationMessage( "Password must contain at least one lowercase letter, one uppercase letter, one digit, one special character, and be at least 8 characters long." ); } }; return ( <div className="container"> <label htmlFor="password" className="label"> React Js Password Validation Regex: </label> <div className="input-container"> <input type={showPassword ? "text" : "password"} id="password" value={password} onChange={(e) => setPassword(e.target.value)} onInput={validatePassword} className="password-input" /> <button onClick={() => setShowPassword(!showPassword)} className="password-button" > {showPassword ? "Hide" : "Show"} </button> </div> {showValidationMessage && ( <span className="validation-message">{validationMessage}</span> )} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> /* Assuming you are using React (as indicated by the className attribute) */ .container { max-width: 400px; margin: 0 auto; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); font-family: Arial, sans-serif; } .label { display: block; font-weight: bold; margin-bottom: 10px; } .input-container { position: relative; } .password-input { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; outline: none; box-sizing: border-box; } .password-button { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); background-color: #fff; border: none; cursor: pointer; font-size: 14px; color: #666; text-transform: uppercase; padding: 5px 10px; border-radius: 5px; outline: none; transition: background-color 0.3s ease; } .password-button:hover { background-color: #f1f1f1; } .validation-message { display: block; color: #c00; margin-top: 5px; font-size: 14px; } </style> </body> </html>