Vuetify Rule Input Text only Accept Number and Dot

Vuetify Rule Input Text: How to Accept Only Numbers and Dots, with Example:Vuetify, a popular Vue.js framework, provides a convenient way to create custom validation rules for form inputs. In this tutorial, we will walk you through the process of setting up a custom rule for a Vuetify text field that only accepts numbers and dots. We will provide a step-by-step example of how to implement this rule in your Vue.js application, ensuring that users can enter valid numerical data effortlessly.

Profile Photo

Abhishek Yadav (SD) SDE of FAI

Feedback

written
Profile Photo

Anil Kumar (Expert) Coding Expert of FAI

Feeback

reviewed
Profile Photo
Nov 04, 2023 03:11 AM Last Updated
updated

Vuetify Rule Input Text: Create a custom rule for numbers and dots

Creating the Vuetify Text Field

To get started, we'll create a Vuetify text field that will accept only numbers and dots. Here's a sample code snippet to help you set up your input field:

Copied to Clipboard
Run

In this code, we have a Vuetify text field with a label, and we bind its value to the inputValue property using v-model

Next, we'll define the Vue.js component responsible for handling this input field. We'll include the necessary data and computed properties to enforce our custom rule.

Copied to Clipboard

In this script section, we create a Vue.js instance, set up the inputValue data property to store the text field's value, and define the inputRules computed property. The inputRules property contains a function that validates the input based on a regular expression. If the input contains only numbers and dots, it is considered valid; otherwise, an error message is displayed.

Output of Vuetify Rule Input Text: Validate input for numbers and dots

Pasted Image

Conclusion:

By following this example, you can easily create a custom rule for a Vuetify input field that restricts input to numbers and dots. This can be particularly useful when you need to ensure that users enter numerical data, such as currency amounts or decimal values. 

Ad