Search code examples
vue.jsvee-validate

using multiple validation with regex in VeeValidate and VueJs


I am applying multiple validation using VeeValidate in a latest VueJs application but that is not working. This regex is to allow only alphabet,number,space and a few special characters. However, VeeValidate always returns false.

                                     <ValidationProvider name="Address"
                                            :rules="{
                                                     required: true,
                                                     max:25, 
                                                     regex:'/[a-zA-Z0-9\\s_@./#&:;+-]*$/'}"
                                            v-slot="validationContext">
                            <b-form-group id="lbl-city" label="*Address:">

                                <b-form-input id="txt-customer-address"
                                              v-model="formData.address"
                                              placeholder="Enter Address"
                                              :state="getValidationState(validationContext)"
                                              aria-describedby="input-3-feedback">
                                </b-form-input>
                                <b-form-invalid-feedback id="input-3-feedback">
                                    {{ validationContext.errors[0] }}
                                </b-form-invalid-feedback>
                            </b-form-group>
                        </ValidationProvider>

any suggestion?


Solution

  • I found the problem.

    [1] Regex was wrong and initially missing ^ symbol [2] \s in regex was allowing space so I added space at last in my regex

    So the final regex is regex:/^([a-zA-Z0-9_@;: ])*$/,

    Now, It only accept Alphabet,Number,Space and following characters @;;_