v-filter
//https://jsfiddle.net/z57f9yLh/
//@author: https://jsfiddle.net/user/airyman/fiddles/
<template>
<div id="app">
<input type="text" v-filter="'[a-zA-Z]'" v-model="message">
</div>
</template>
<script>
Vue.directive("filter", {
bind: function(el, binding) {
this.inputHandler = function(e) {
var ch = String.fromCharCode(e.which);
var re = new RegExp(binding.value);
if (!ch.match(re)) {
e.preventDefault();
}
};
el.addEventListener("keypress", this.inputHandler);
},
unbind: function(el) {
el.removeEventListener("keypress", this.inputHandler);
},
inputHandler: null
});
new Vue({
el: "#app",
data: {
message: "Ivan"
}
})
</script>