Léo Coco
Léo Coco

Reputation: 4282

Vue.js - Element UI - Form validation regexp

I'd like to validate a form using vue-js 2.3 and element-ui

Apparently, they use async-validator to validate the form. The documentation is here.

Example

https://jsfiddle.net/skd3nyqh/

Problem

Uncaught Error: Unknown rule type D*([2-9]d{2})(D*)([2-9]d{2})(D*)(d{4})D*

I do not know how to validate a field with regexp. I find the documentation not explicit enough on that topic.

Upvotes: 8

Views: 18059

Answers (1)

Bert
Bert

Reputation: 82489

From the documentation.

Pattern

The pattern rule property indicates a regular expression that the value must match to pass validation.

Use

{required: true, pattern:/\D*([2-9]\d{2})(\D*)([2-9]\d{2})(\D*)(\d{4})\D*/, message: 'Please input phone', trigger: 'blur' }

Updated fiddle.

Upvotes: 12

Related Questions