Vee-validate—I want to add a regular expression validation rule in js after object generation

Asked 2 years ago, Updated 2 years ago, 55 views

As the title says, I would like to add validation rules using vee-validate.
(for example, telphone num should be required &&\d{11})

I'm in trouble because there's no way to do it even if I look at the official documents.
https://vee-validate.logaretm.com/api.html#validator-fields

If you use regular expressions, you will get syntax errors even if you specify the following:

Working Example

this.$validator.attach({name:"tel", rules:"required"});

Example Not Working

this.$validator.attach({name:"tel", rules:"{required:true, regex:/\d{11}/}"});

This part is "unexpacted token:".

"{required:true, regex:/\d{11}/}'"

If you know more, please take care of me.

vue.js

2022-09-29 21:26

1 Answers

this.$validator.attach({name:"tel", rules:"{required:true, regex:/\\d{11}/}}); 


2022-09-29 21:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.