Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zxtanzxzx's avatar

Vue js, Restrict Length of <input />

I wanted to create a client side validation where it can detect the input value length and stop accept any input once it reach a length of 4.

I google a lot but mostly are jquery related, is there anyway to do it using vue?

0 likes
6 replies
zxtanzxzx's avatar

@EEETM - I saw this earlier, it's using vue assigned value to the html maxlength attribute, what i was looking is full vue.js solution, Thanks thou!

ohffs's avatar
ohffs
Best Answer
Level 50

Would a simple filter do? Or you could use a watcher on the value and just trim the length? Either that or bind the value and input events separately and do it in the event handler I guess.

Eeetm's avatar
<input v-validate="'length:4'" type="text" name="field">

Please or to participate in this conversation.