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 [address, setAddress] = useState('1Lbcfr7sAHTD9CgdQo3HTMTkV8LK4ZnX71'); const [isValid, setIsValid] = useState(false); const [isMessageVisible, setMessageVisible] = useState(false); const validateAddress = () => { const regEx = /^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/; if (regEx.test(address)) { setIsValid(true); } else { setIsValid(false); } // Show the message when validation is performed setMessageVisible(true); }; return ( <div className='container'> <h3 className='heading'>React Js Bitcoin Address Validator</h3> <input type="text" className='input-field' placeholder="Enter a Bitcoin address" value={address} onChange={(e) => setAddress(e.target.value)} /> <button className='validate-button' onClick={validateAddress}> Validate Address </button> {isMessageVisible && ( <p className='message'> {isValid ? <span style={{ color: 'green' }}>The Bitcoin address is valid.</span> : <span style={{ color: 'red' }}>The Bitcoin address is not valid.</span> } </p> )} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 600px; 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; } heading { font-size: 24px; margin-bottom: 20px; color: #333; } .input-field { padding: 10px; width: 300px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; margin-bottom: 10px; outline: none; } .validate-button { padding: 10px 20px; background-color: #007BFF; color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 18px; transition: background-color 0.3s; } .validate-button:hover { background-color: #0056b3; } .message { font-size: 18px; margin-top: 20px; color: #007BFF; } </style> </body> </html>