8

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.

3
  • When I run your fiddle, I see no such error in my console. Commented Jun 6, 2017 at 17:15
  • I just did it again jsfiddle.net/skd3nyqh :/ Commented Jun 6, 2017 at 17:16
  • Ok, the error shows now. Commented Jun 6, 2017 at 17:17

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Very sound answer, but is there not any way to implement this pattern globally for whole Element-UI Component?

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.