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; function App() { const [pin, setPin] = useState(''); const handlePinChange = (e) => { const value = e.target.value; const maskedValue = value.replace(/\D/g, '').slice(0, 4); // Allow only digits and limit length to 4 setPin(maskedValue); }; return ( <div className='container'> <h3>React Js Input Mask for 4 Digit Pin</h3> <label className='label'>4 Digit Pin:</label> <input className='input' type="text" value={pin} onChange={handlePinChange} placeholder="Enter 4-digit PIN" maxLength={4} /> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { display: flex; flex-direction: column; align-items: center; margin: 0 auto; padding: 20px; width: 600px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } .label { font-size: 16px; margin-bottom: 10px; } .input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; outline: none; transition: border-color 0.3s; } .input::placeholder { color: #999; } .input:focus { border-color: #007bff; } </style> </body> </html>