screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> </head> <body> <div id="inputContainer"> <h1>Javascript only 1 space and Alphabets Allowed</h1> <label for="inputField">Enter text:</label> <input type="text" id="inputField"> <button onclick="validateInput()">Validate</button> <p id="result"></p> </div> <script> function isValidInput(input) { // Allow only single spaces and alphabets return /^[a-zA-Z]+(?:\s[a-zA-Z]+)?$/.test(input); } function validateInput() { let userInput = document.getElementById("inputField").value; let resultElement = document.getElementById("result"); if (isValidInput(userInput)) { resultElement.innerText = "Input is valid"; resultElement.className = "valid"; } else { resultElement.innerText = "Invalid input"; resultElement.className = "invalid"; } } </script> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; display: flex; align-items: center; justify-content: center; height: 100vh; } #inputContainer { text-align: center; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } label { font-size: 18px; display: block; margin-bottom: 10px; } input { padding: 10px; font-size: 18px; width: 250px; margin-bottom: 15px; border: 2px solid #3498db; border-radius: 5px; outline: none; transition: border-color 0.3s ease-in-out; } input:focus { border-color: #2ecc71; } button { padding: 10px 20px; font-size: 16px; background-color: #4caf50; color: #fff; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } #result { font-size: 18px; margin-top: 10px; color: black; } #result.valid { color: green; } #result.invalid { color: red; } </style> </body> </html>