Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

javascript - How to prevent specific special characters from being added to v-textfield or v-textarea

How to prevent users from adding dots, slashes or spaces consecutively by controlling inputs to v-textarea with regular expressions

for example

             <v-textarea
          :maxlength="max"
          :error-messages="appDescriptionErrors"
          v-model="appDescription"
          background-color="amber lighten-4"
          color="amber-darken-4"
          :label="
            'Randevu A??klamas?( Kalan karakter say?s?:' +
            (max - appDescription.length) +
            ')'
          "
          @input="$v.appDescription.$touch()"
          @blur="$v.appDescription.$touch()"
        ></v-textarea>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Its really not very clear what exactly you want but generally you have two options:

  1. Use special library like v-mask to set exact format of input user can type - the lib will block any characters not allowed

  2. As you are already using Vuelidate, just use some of the build-in validators as required + minLength + alpha. If that's not enough, use regex based validator. This way user can type whatever he wants, but Vuelidate will show him an error.....


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...