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 Validate CVV Number</h3> <label for="cvv">CVV Number:</label> <input type="text" id="cvv" v-model="cvv" @input="validateCVV" /> <p v-if="!isValidCVV" class="error">Invalid CVV number.</p> </div> <script type="module"> const app = Vue.createApp({ data() { return { cvv: '', isValidCVV: true, }; }, methods: { validateCVV() { // Remove any non-digit characters const cleanedCVV = this.cvv.replace(/\D/g, ''); // CVV should be a 3 or 4 digit number const isValidLength = cleanedCVV.length === 3 || cleanedCVV.length === 4; // Update the validity flag this.isValidCVV = isValidLength; }, }, }); app.mount('#app'); </script> <style> .error { color: red; font-weight: bold; } #app { width: 400px; margin: 20px 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 } label { display: block; margin-bottom: 5px; } input[type="text"] { padding: 5px; border: 1px solid #ccc; border-radius: 3px; width: 200px; } input[type="text"]:focus { outline: none; border-color: #007bff; } </style> </body> </html>