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 Validate Ip Address</h3> <input v-model="ipAddress" type="text" placeholder="Enter IP address" /> <p v-if="!ipAddress">Please enter an IP address</p> <p v-else-if="!isValidIpAddress">Invalid IP address</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { ipAddress: '192.168.0.1' }; }, computed: { isValidIpAddress() { const ipAddressPattern = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/; return ipAddressPattern.test(this.ipAddress); } } }); </script> <style> #app { text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); width: 600px; margin: 0 auto; padding: 20px; } input[type="text"] { padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; width: 300px; max-width: 100%; } p { margin: 10px 0; color: red; font-size: 14px; } </style> </body> </html>