screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <div id="app"></div> <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://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> <script type="text/babel"> const { useState, useRef } = React; function App() { const inputRef = useRef(null); const [error, setError] = useState(''); const handleSubmit = (event) => { event.preventDefault(); const minValue = 50; // Set your minimum value here const maxValue = 100; // Set your maximum value here const inputValue = inputRef.current.value; if (isNaN(inputValue) || inputValue < minValue || inputValue > maxValue) { setError(`Value must be between ${minValue} and ${maxValue}`); } else { console.log(`Valid value: ${inputValue}`); setError(''); } }; return ( <div className='container'> <form onSubmit={handleSubmit} className="form"> <label className="label"> Enter a number: <input type="number" ref={inputRef} className="input" /> </label> <button type="submit" className="button">Submit</button> {error && <div className="error">{error}</div>} </form> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 400px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; } /* Label */ .label { display: block; margin-bottom: 10px; font-weight: bold; } /* Input */ .input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; outline: none; } /* Button */ .button { background-color: #007bff; color: #ffffff; border: none; border-radius: 5px; padding: 10px 20px; font-size: 16px; cursor: pointer; } .button:hover { background-color: #0056b3; } /* Error Message */ .error { color: #ff0000; margin-top: 10px; } </style> </body> </html>