0

I need to perform multiple validations on a field in vuetify, for example the identity field must have 11 characters, and all must be numeric, I am using this code but it validates the quantity and if it is numeric or not only in the first character that is written.Could you guide me how to solve this problem?

This is part of the code that I am using

       <v-col cols="4" sm="4" md="4">
        <v-text-field
          label="Identidad*"  
          v-model.number="editedItem.identidad"
          :rules ='inputidentidadrules'
          counter="11"
          error-count="2"
          required/>
     </v-col>

.......
 export default {
         data: () => { 
           return {
            dialog: false,
            search: '',
            isFormValid: false,
       inputidentidadrules:[
                (v) => v.toString().length >=11 || 'Longitud 11 caracteres',
                (v) => !isNaN(parseFloat(v)) || 'El valor debe ser numérico'
             ],
.......


1
  • Try to add a working example of code on codepen / code sandbox! which will help to debug Commented Jun 5, 2020 at 6:03

2 Answers 2

1

Try below rule and remove .number from v-model ie use v-model="editedItem.identidad"

         inputidentidadrules:[
            (v) => /^\d+$/.test(v)||'El valor debe ser numérico',
            (v) => (v && v.length > 10) || 'Longitud 11 caracteres'
         ],
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for your suggestions, I was able to solve combining part of your solution with that of @hardik
0

try this one below rule is related to checking for valid 11 digit

inputidentidadrules:[(v) => /^\d{11}$/.test(v) || 'Enter valid 11 digit']

1 Comment

Thank you very much I found your answer useful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.