I only want the field name
to accept numbers and letters, while the field number
should only allow numbers.
How can I achieve this? Where can I find documentation that explains it clearly?
const app = new Vue({
el: '#app',
data: {
name: null,
number: null
},
methods: {
checkForm: function (e) {
if (this.name) {
return true;
}
if (!this.name) {
console.log("Required");
}
if (this.number) {
return true;
}
if (!this.number) {
console.log("Required");
}
e.preventDefault();
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<form id="app" @submit="checkForm" method="post" novalidate="true">
<p>
<label for="name">Name</label>
<input id="name" v-model="name" type="text" name="name">
<input id="number" v-model="number" type="text" name="number">
</p>
<input type="submit" value="Submit">
</form>
Many thanks!