Im using Vuetify and trying to get a text-area to validate ONLY if there are more than 200 characters.
I want to ONLY make the field validate if the user has 1 or more characters, but be less than 200 characters IF it is at least 1 character. This filed is not required BUT if they choose to type data into it i want to make sure its is 200 characters or less.
<v-textarea
v-model="description"
:counter="200"
:rules="[v => (v && v.length <= 200) || 'Description must be 200 characters or less']"
label="Description"
height="125"
no-resize
outline
/>
Im using Vuetify and trying to get a text-area to validate ONLY if there are more than 200 characters.
I want to ONLY make the field validate if the user has 1 or more characters, but be less than 200 characters IF it is at least 1 character. This filed is not required BUT if they choose to type data into it i want to make sure its is 200 characters or less.
<v-textarea
v-model="description"
:counter="200"
:rules="[v => (v && v.length <= 200) || 'Description must be 200 characters or less']"
label="Description"
height="125"
no-resize
outline
/>
Share
Improve this question
edited Jul 17, 2020 at 18:18
Boussadjra Brahim
1
asked Jul 26, 2019 at 22:41
user616user616
8555 gold badges19 silver badges53 bronze badges
2 Answers
Reset to default 8According to this example
provided in official docs, i see that you should do something like :
:rules="[v => (v || '' ).length <= 200 || 'Description must be 200 characters or less']"
For shorter strings, I ended using something like this:
min: v => (v || 'aaaa' ).length >= 4 || '4 chars minimum'