How it works...

We are using a native HTML5 validation API, which internally uses pattern matching to check whether what we are typing is conformant to certain rules.

Consider the attribute required in the following line:

<input type="text" required>

This ensures that when we submit the form, the field is actually populated, while having type="email" in the other input element ensures that the content resembles an e-mail format.

This API is very rich and you can read more at https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation.

Many a times, the problem is that to leverage this API, we need to trigger the native validation mechanism. This means that we are not allowed to prevent the default behavior of the ...

Get Vue.js 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.