How can I troubleshoot email validation issues in Vue.js?

    <button type="submit"
                      class="register-button"
                      :class="(isDisabled) ? '' : 'selected'"
                      :disabled='isDisabled'
                      v-on:click=" isFirstScreen"
                      @click="persist" >
                      PROCEED
   </button>

email:'',
maxemail:30,
 
   validationStatus: function (validation) {
      return typeof validation != "undefined" ? validation.$error : false;
    },
    
 computed: {
    isDisabled: function(){

      return (this.fullname  <= this.max) || (this.mobile.length < this.maxmobile)
      || (this.gstin.length < this.maxgstin) ||
       (this.email <= this.maxemail) || !this.terms || !(this.verified == true );
     
}

    isEmail(e) {

      if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value))
      {
        this.msg['email'] = '';
      } else{
        this.msg['email'] = 'Invalid Email Address';
      } 
    
      
    },
 <input
                      type="email"
                      v-model.trim="$v.email.$model"
                      v-validate="'required'"
                      :class="{ 'is-invalid': validationStatus($v.email) }"
                      name="email"
                      class=" input-section"
                      placeholder="Enter your company email ID"
                      :maxlength="maxemail"
                      v-on:keypress="isEmail($event)"
                       id='email'  v-model='email'
                    />
   <div v-if="!$v.email.required" class="invalid-feedback">
                      The email field is required.
                    </div>
                 
                    <div v-if="!$v.email.maxLength" class="invalid-feedback-register">
                       30 characters only
                      {{ $v.user.password.$params.maxLength.min }} 
                    </div>

Currently facing issues with email address validation. Even after entering a short email address, the button gets enabled and moves to the next page. I need the button to be disabled until a valid email address is entered. Any help on resolving this issue with the provided code would be appreciated.

Answer №1

Follow these steps to resolve the issue.

Step 1: Start by installing vuelidate using npm install --save vuelidate

Step 2: Register vuelidate in your main.js file

import Vuelidate from 'vuelidate'
Vue.use(Vuelidate)

Step 3: Import validators like

required, email, minLength, sameAs
from vuelidate/lib/validators

import { required, email, minLength, sameAs } from 'vuelidate/lib/validators'

Step 4: Add the necessary validations

validations: {
 user: {
    name: { required },
    email: { required, email },
    password: { required, minLength: minLength(6) },
    confirmPassword: { required, sameAsPassword: sameAs('password') }
  }
},

Step 5: Implement validation when the button is clicked

methods: {
 submitRegistration () {
   this.submitted = true
   this.$v.$touch()
   if (this.$v.$invalid) {
     return false // stop here if form is invalid
   } else {
     alert('Form Valid')
   }
  }
}

Step 6: Design your HTML template for the form

 <template>
  <div>
    <form @submit.prevent="submitRegistration" novalidate>
      <!-- Form fields and error messages go here -->
    </form>
  </div>
</template>

Step 7: Disable the button until the form is valid

created () {
  this.submitted = true
  return this.$v.$touch()
},
computed: {
  isDisabled () {
    return this.$v.$invalid
  }
},

For a demonstration, you can visit https://github.com/Jebasuthan/vue-vuex-vuelidate-i18n-registration-login-todo

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

When working with THREE.js in Electron, web development tools seem to vanish into thin air

Exploring electron is fairly new to me (if you know of any good documentation, please leave it in the comments) and I've encountered an issue that has left me puzzled: Everything seems fine until I load the THREE.js library. At that point, even thoug ...

Use jQuery Ajax to fetch an image and display it on the webpage

Currently, I am working on an application that is designed to browse through a large collection of images. The initial phase of the project involved sorting, filtering, and loading the correct images, as well as separating them into different pages for imp ...

Animating a group of images with JQuery

Hey there! I've been working on a simple animation for my webpage, but I'm having some trouble getting it to work the way I want. You can check out my page at . What I'm trying to achieve is having each image appear at its final position an ...

Should we define all public methods or prototype each method separately?

Typically, when I create a library, my approach is as follows: var myLibrary = (function() { return { publicProperty: 'test', publicMethod: function() { console.log('public function'); }, ...

Guide to creating a custom wrapper for a Material UI component with React JS

I am utilizing the Material UI next library for my project and currently working with the List component. Due to the beta version of the library, some parameter names are subject to change. To prevent any future issues, I have decided to create a wrapper a ...

Top method for saving information on page for Ajax calls

On my dynamically generated page, there is an array of data produced by php that I want to utilize for an ajax request. However, I am unsure of the best method to store this data on the page as it is not sensitive and does not involve a form. Currently, I ...

Have you ever wondered how to disable a tooltip in React Material UI after clicking on it? Let

I am working with a Material-UI tab component and I would like to include a tooltip feature. The issue I am facing is that the tooltip does not disappear when I click on the tab. It should hide after clicking on the tab. Currently, the tooltip remains vi ...

Express string declaration in a single TypeScript line

const restrictString = (str: string): string => str.match(/[ab]/g)?.join('') || '' Is there a way to restrict a string to only contain the characters 'a' and 'b' in a one-liner function? I am aware that this can ...

Personalize the error message for throwing an exception in JavaScript

I've been working on customizing error messages for exceptions thrown in JavaScript. Despite my best efforts, I have not been successful so far. I'm currently attempting the following code snippet but it's not functioning as expected: f ...

Ionic: setInterval/setTimer not functioning after 5 minutes in the background

In need of a timer that can send notifications via the OneSignal API after a user-defined time period is reached. Users can set the timer for any value between 1-59 minutes. Despite attempts to use the background mode plugin, specifically setInterval and s ...

Creating getter and setter functions for an input field model property in Angular

I need help creating getter and setter methods for an input field property. Here is my attempted code: import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', st ...

Tips for creating a multi-step wizard using AngularJS and incorporating AJAX calls---Crafting a multi

Exploring the creation of a multi-step wizard with ajax calls: Utilizing ui.router for managing views of the wizard steps, the first page prompts users to input data such as playerid. The second page aims to display information retrieved from the server b ...

Styling for older versions of Internet Explorer (IE10 and earlier)

Could it be true that IE 10, 9, and others no longer support conditional statements? Is it also accurate to say that JQuery does not support the browser object above version 1.9? I am facing an issue with CSS rendering differently in Chrome and IE. A Goog ...

I am looking to sort through the data based on the courseCode, but I can't seem to find a way to do it

Here is the JSON data after converting it with res.json() I attempted to filter it based on course code, let's say the code is: 301. I am confused about how to achieve this using JavaScript because of the nested structure. Here is the code snippet I ...

When using my webrtc technology, I configure my sdp to establish a recvonly direction

While attempting to make a video call using WebRTC, I encountered bugs during testing. My goal is to integrate this project into a webview for my Android app. I conducted testing using phone-pc and phone-phone scenarios. Scenario A: When the PC initialize ...

Unable to access the suggestion list within the modal

I incorporate the PrimeNG AutoComplete feature within a PrimeNG Dialog, displaying a list of elements below the AutoComplete in the dialog. My objectives are: To set the max-height of the modal dialog to 300, and have a visible scrollbar if the total ...

Troubleshooting: Unable to locate .vue.d.ts file during declaration generation with Vue, webpack, and TypeScript

Currently, I am developing a library using Typescript and VueJS with webpack for handling the build process. One of the challenges I'm facing is related to the generation of TypeScript declaration files (.d.ts). In my source code, I have Typescript ...

Annoying scrolling issue arising from using jQuery Buttonset

Dealing with jQuery UI buttons and buttonsets has been quite a challenge for me. Despite searching extensively on this site, I have yet to find a satisfactory solution that works smoothly. My setup includes jQuery rev 1.11.1 and jQuery UI rev 1.9.2. The i ...

Bootstrapvalidator does not function properly with select2.js

My code is not validating the select field. What could be causing this issue? Can anyone provide a solution? Apologies for my poor English, and thank you in advance for your response. Here is my form: <form name="form_tambah" class="form_tambah"> ...

Step-by-Step Guide on Retrieving Filtered Data using React Context API

Currently, I am in the process of developing a dashboard application using React.js, React Context API, and ApexCharts. The app will visualize a 1000-length JSON data on 7-8 different charts, along with 6-7 variable filters. Overview of the App Structure: ...