Vue Input Number Only
In this tutorial, we will learn how to use Vue 3 to accept only numbers in an input field. We will provide two examples to achieve this. In the first example, we will use Vue 3 Composition API and regex. In the second example, we will use Vue 2 Options API and the charcode method.
written
reviewed
updated
Thanks for your feedback!
Your contributions will help us to improve service.
Example 1 : Accept Only Numbers in Input Type Text using Vue 3
In this example, we will see how to prevent non-numeric characters in an input field using Vue 3 and the regex method.
Example 2: How to Make Input Accept only Numbers in Vue Js (Options Api)?
This code below demonstrates how to allow only numbers in a text field, such as a phone number. We use the Vue charcode method to achieve this.
Output of Prevent Non Numeric Input in Vue Js
Ad