What are some effective methods for validating input in a Skeleton and Vue.js environment?

I really appreciate these tools for their simplicity and compactness. However, as a backend developer with weak JS skills, I sometimes struggle with the lack of plugins/snippets. Here's one such scenario:

For instance, I have a straightforward form like this:

<div class="row">
    <div class="six columns">
        <label for="email">Contact email*</label>
        <input v-model="email" class="u-full-width" type="email" id="email" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c3d383135321c39243f343d323b39723f3331">[email protected]</a>" name="email">
    </div>
    <div class="six columns">
        <label for="date">Launch date*</label>
        <input v-model="date" class="u-full-width" type="text" id="date" placeholder="June, 2014">
    </div>
</div>

Here, I aim to make these fields required, with the email input formatted like ***@***.***, while the date field can accept any value.

What is the optimal approach to achieve this? Also, I've come across 3 Vue plugins - do you have a preferred one?

Thank you for any examples, snippets, etc.

Answer №1

Given your background in backend development and lack of expertise in JavaScript (which I can totally relate to :D), I recommend giving it a go yourself. You'll benefit from the learning experience.

Here's my suggested approach:

<input name="email" v-model="email" @keyup="validateEmail()" />

... Vue component or instance ...
data: function() { // If you're working with a Vue instance instead of a component, the data property will be structured differently. In a component, it must be a function that returns an object.
  return {
    email: ""
  }
},
methods: {
  validateEmail: function() {
    console.log(this.email);
    // Now that the email input is changing, you can utilize regex, substring manipulation, or other string operations to determine if the string meets your criteria.
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Establish the container with a specific height and enable scrolling functionality

Here is the code snippet I am currently working with: <section class="table"> <div class="table-row"> <div class="table-cell"></div> <div class="table-cell"></div> <div class="table-cell"></div> ...

Vue AG-Grid showcases specially designed components while fetching the rows

I have been attempting to show the v-progress-circular Vuetify component while ag-grid is loading rows. Following the ag-grid documentation has not been successful as it appears to be outdated for Vue. Below is what I have tried so far: TableProgress.vue ...

Vuex state fails to reflect the updated data

I have integrated Vuex with axios to retrieve data from my backend. However, I am facing an issue where the state property userName is not updating within my Vue Single File Component(SFC). approot.js state const state = { userName: 'foo&apo ...

Extract SCSS import filepaths using NPM and Gulp

Currently, in my gulp setup, I have several CSS files being produced - a general 'core' one, and then template-specific stylesheets. Instead of re-compiling all stylesheets with each change, the setup only compiles the necessary ones. However, t ...

What is the best way to ensure jQuery loads before CSS code on a website

I am currently working on a blog project that allows visitors to customize the background color by simply clicking on one of five available buttons. $(function(){ //Checking if a color scheme has already been selected var chosenColor = ...

What is the best way to organize blog posts by using hashtags?

I am looking to implement a filtering system for blog posts using hashtags. This feature should display only the blog posts with matching hashtags and move them to the top of the page. Additionally, there should be a button at the top to show all posts. ...

When utilizing Vuetify's v-menu feature, only the initial click will trigger the menu display

 The Challenge I'm Facing Currently, I am developing a calendar using Vuetify and integrating drag-and-drop functionality along with event clicking. One key feature I added is the ability to change event color through a v-menu popup that appears up ...

Saving the reference of a Fabric.js Canvas in Vuex - [vuex] refrain from altering the vuex store state outside of mutation handlers

I'm developing a Vue Application that utilizes Fabric.js to manage the canvas element. My goal is to control the canvas state through Vuex. To achieve this, I have assigned the fabric canvas instance to a Vuex state variable. Mutation setCanvas(sta ...

Scrollable container with jQuery draggable functionality

I am currently working on implementing a draggable list that I want to contain within a scrollable div. $( ".draggable" ).draggable(); Here is the fiddle I have created for this: http://jsfiddle.net/YvJhE/660/ However, the issue I am facing is that the ...

What could be the reason for the SVG gradient not appearing in Explorer?

Check out my website at Everything was working smoothly with the background for the top menu, but suddenly it stopped working. The strange thing is, I only made adjustments to the position settings of some unrelated elements. ...

Merging onsubmit attribute with jQuery submit event listener

My website has a form that is automatically generated by older server-side code. Unfortunately, I am unable to make any modifications to this legacy code for various reasons. The form itself is written in straightforward HTML: <form action="#" id="theF ...

What's the best way to implement the correct styles for an element-plus message box?

I recently created a minimal page and integrated the Element-Plus message box. However, the appearance of the message box was different from what I expected based on the Element-Plus documentation. My setup includes Vue, Vite, and ElementPlus. I followed ...

Creating an installation-ready Progressive Web App with Vue.js: A step-by-step guide

I am looking to add the functionality of installing my Vue app as a PWA in Chrome or Firefox with the click of a button. <button @click="install">install</button> var deferredPrompt methods: { install() { deferredPrompt.promp ...

The tale of a div's mysterious empty room

Once upon a time, in the world of HTML and CSS, there existed a lonely div. This lonely div longed for companionship, and one day, an inline img came to visit. They formed a bond and became good friends. But, no matter how hard the img tried, it couldn&apo ...

What is the best way to determine font size based on the width of the

In order to ensure that certain elements on my page do not exceed specific widths, it is crucial for me to use a monospaced font. This will limit the horizontal "stride" between characters to stay within a specified threshold. However, simply setting the ...

What is the best way to align HTML elements in a single row?

I have the following code snippet... <div class="header"> <div class="mainh"> <div class="table"> <ul> <li><a>smth</a></li> ...

Creating a consistent visual appearance for disabled inputs in Bootstrap 4 to match regular inputs

In most cases, when an input is disabled in bootstrap 4, it appears greyed-out to show that it's inactive. I am looking into removing this grey background for a different look. ...

What is the best way to optimize Bootstrap 5 grids for mobile responsiveness?

Within my portfolio, I have a projects section that switches between having the description on the left with an image on the right and vice versa. Despite my efforts to make it responsive, I'm struggling to figure out how to ensure the image appears a ...

Attempting to display images in various formats using the Picture HTML element

Vue is being used to create a dynamic picture component, resulting in the following code: <picture style="display: contents;"> <source type="image/avif" sizes="700px" src ...

A Vue computed property is returning the entire function instead of the expected value

One of my computed properties is set up like this: methods: { url_refresh: function (id) { return `${this.url_base}?start=${Date.now()}` } } However, when I attempt to print the value on mount: mounted() { console.log(this.url_refresh) ...