screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; const App = () => { const [inputValue, setInputValue] = useState(''); const [error, setError] = useState(''); const minLength = 10; // Minimum length requirement const handleChange = (e) => { setInputValue(e.target.value); }; const handleBlur = () => { if (inputValue.length < minLength) { setError(`Input must be at least ${minLength} characters long.`); } else { setError(''); } }; return ( <div className='container'> <h3>React Js Input Min Length</h3> <label> Minimum Length Input: <input type="text" value={inputValue} onChange={handleChange} onBlur={handleBlur} // Handle blur event /> </label> {error && <p className="error">{error}</p>} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { border-radius: 8px; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1); padding: 20px; margin: 20px auto; max-width: 600px; text-align: center; } h3 { color: #333; } label { display: block; margin-bottom: 10px; font-weight: bold; } input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; box-sizing: border-box; } .error { color: red; font-size: 14px; } </style> </body> </html>