screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { font-family: 'Arial', sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f4f4f4; } #input-container { text-align: center; } input[type="text"] { padding: 12px; font-size: 18px; border: 2px solid #3498db; border-radius: 8px; outline: none; transition: border 0.3s ease-in-out; } input[type="text"]:focus { border-color: #007BFF; /* Change border color on focus */ box-shadow: 0 0 8px rgba(0, 123, 255, 0.6); /* Add a subtle box shadow */ } #error-message { color: #e74c3c; display: none; margin-top: 5px; } </style> <script> function allowAlphanumericOnly(event) { var charCode = event.which || event.keyCode; if ((charCode < 48 || charCode > 57) && (charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122)) { event.preventDefault(); displayErrorMessage(); } else { clearErrorMessage(); } } function displayErrorMessage() { document.getElementById("error-message").style.display = "block"; } function clearErrorMessage() { document.getElementById("error-message").style.display = "none"; } </script> </head> <body> <div id="input-container"> <h1>Allow Only Alphanumeric in Textbox using Javascript</h1> <input type="text" onkeypress="allowAlphanumericOnly(event)"> <p id="error-message">Please enter only alphanumeric characters.</p> </div> </body> </html>