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 input mask credit card expiry date</h3> <input type="text" v-model="expirationDate" @input="handleInput" placeholder="MM/YY" maxlength="5" /> </div> <script type="module"> const app = Vue.createApp({ data() { return { expirationDate: '', }; }, methods: { handleInput(event) { let input = event.target.value; // Remove any non-digit characters input = input.replace(/\D/g, ''); // Add slash after the first two characters if necessary if (input.length > 2) { input = input.slice(0, 2) + '/' + input.slice(2); } // Update the input field value this.expirationDate = input; }, }, }); app.mount('#app'); </script> <style> #app { width: 400px; margin: 0 auto; padding: 20px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); } h3 { font-size: 20px; margin-bottom: 10px; } input[type="text"] { padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; width: 120px; box-sizing: border-box; outline-color: lightblue; } </style> </body> </html>