screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Text field allow only 10 digt number</h3> <input v-model="phoneNumber" v-on:input="limitPhoneNumber" /> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { phoneNumber: "1234567890" }; }, methods: { limitPhoneNumber() { // Remove any non-digit characters from the phone number this.phoneNumber = this.phoneNumber.replace(/\D/g, ""); // Limit the phone number to 10 digits if (this.phoneNumber.length > 10) { this.phoneNumber = this.phoneNumber.substring(0, 10); } } } }); </script> <style scoped> #app { display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 50px auto; } h3 { font-size: 20px; margin-bottom: 20px; } input { padding: 10px 15px; font-size: 16px; border-radius: 5px; border: 1px solid #ccc; outline: none; transition: border-color 0.3s ease-in-out; } input:focus { border-color: #0074d9; } </style> </body> </html>