screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.12/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Js Textbox allow only small letters</h3> <input type="text" v-model="inputValue" @keydown="restrictInput" /> <div v-if="!isInputValid" class="error-message">Only small letters are allowed.</div> </div> <script> const app = Vue.createApp({ data() { return { inputValue: '', isInputValid: true }; }, methods: { restrictInput() { this.isInputValid = /^[a-z]*$/.test(this.inputValue); this.inputValue = this.inputValue.replace(/[^a-z]/g, ''); } } }); app.mount('#app'); </script> <style> #app { width: 400px; margin: 0 auto; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); text-align: center; padding: 20px; height: 100%; } .error-message { color: red; font-size: 14px; margin-top: 5px; } input[type="text"] { padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; outline-color: blue; /* Change the color as desired */