最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vuetify text-area empty OR less than 200 character rule - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 8

According 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'
发布评论

评论列表(0)

  1. 暂无评论