Is verifying email and password with jquery possible?

I am currently working on a jQuery form validation project:

While the password and username validation are working fine, I am facing issues with email and password confirmation validations. Surprisingly, I have used the same technique for both.

If you want to check out a demo, click here

The main problem is that even though there are no console errors showing up, the email and password confirmation functionalities are not functioning properly.

HTML

    <title> Sign Up </title>
<body>
<div class=left></div>
<form method="post" action="" >
... [content continues]

jquery

$(document).ready(function () {
... [javascript code continues]
}); 

I don't think providing the CSS code here is necessary (you can find it in the fiddle). I've tried debugging the code by commenting out the username and password validations, and those seem to be fine. So, I believe the issue lies within this part:

$('#pa2').blur(function () {
    
    var pswd2 = $('#pa2').val();
    if(pswd != pswd2)
    {
    $('#pswd2_info').fadeIn();
    }
    else
    {$('#pswd2_info').fadeOut();
    }
    });

and/or in this part:

$('#em').blur(function () {
    function isValidEmail(emailText) {
    ... [email validation function continues]
    };
    if( !isValidEmail(myEmail) )
    {$('#remail').removeClass('valid').addClass('invalid');
    }
    else
    {$('#remail').removeClass('valid').addClass('invalid');}
    }); 
    $('#em').focus(function () {
        // focus code here
    });
    $('#em').blur(function () {
        // blur code here
    });

    $('#em').keyup(function () {

        // keyup code here
    }).focus(function () {
        $('#remail').show();
    }).blur(function () {
        $('#remail').hide();
    }); 

Can anyone spot what might be wrong here?

Answer №1

There are a few issues that need to be addressed.

Email

1) Make sure to give the email input field the appropriate id selector to trigger the blur event correctly.

    <input id='emailInput' type='email' placeholder="Email" name='email'>  

Assign the value of the email input to myEmail in order to avoid any errors.

    $('#emailInput').blur(function () {
    myEmail = $(this).val();

2) Instead of applying classes to a div, consider adding them to a list item within a container element as shown below:

    <div id=emailContainer class=info>
       <h4> The email you entered is invalid: </h4>
       <ul>
         <li id=emailFormat class=invalid> 
           A valid email format should look like this: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1a4a2b4a3bfb0bcb491b4a9b0bca1bdb4ffb2bebc">[email protected]</a>
         </li>
       </ul>
    </div>

Remember to add fade-in and fade-out effects to the container as needed.

      if (isValidEmail(myEmail)){ 
        $('#emailContainer').fadeOut('slow');
      } else {
        $('#emailContainer').fadeIn('slow');
      }

This should resolve the email validation issue. View the updated code snippet here

Password Confirmation

For password confirmation, ensure to use the correct id when selecting the password input field.

  <td><input id='passwordRepeat' type='password' placeholder='Repeat password' name=passwordRepeat></input>

Define both pswd and pswd2 variables to compare the passwords correctly.

  var pswd = $('#password').val();
  var pswd2 = $('#passwordRepeat').val();

These adjustments should fix both email and password confirmation issues. Check out the revised code on this link

Answer №2

Can you spot a mistake in this code?


    if( !checkValidEmail(emailAddress) ){
       $('#email').removeClass('valid').addClass('invalid');
    }
    else{
       $('#email').removeClass('valid').addClass('invalid');
    }

Both of these lines seem to be doing the same thing!

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

jQuery Super-sized Not Expanding Vertically

I am facing an issue with resizing a 1920x1200 background image using jQuery Supersized. Whenever I resize the browser, there is a gap that appears vertically instead of filling up to compensate for the width constraint. I have checked and copied the sett ...

Is there a way to seamlessly combine multiple jQuery event handlers into one?

Upon utilizing jQuery for the first time, I found it to be more convenient than before. However, I encountered a perplexing issue that arises when attempting to combine two almost identical anchors into one. <a class="p" href="javascript:;">ABC< ...

What is the best way to combine a string with a $scope variable in AngularJS?

Is there a way to add a variable to the $scope model in order to concat it? I'm attempting this code: for(var i=0; i<=response.length-1; i++) { $scope.formData.jobId+i = response[i].jobId; } How can I combine the variable i with $scope.formDat ...

What is the process for a server to transmit a JWT token to the browser?

Here is an example response sent to the browser: HTTP / 1.1 200 OK Content - Type: application / json Cache - Control : no - store Pragma : no - cache { "access_token":"MTQ0NjJkZmQ5OTM2NDE1Z ...

Troubleshooting Vue Single File Components Displaying Missing Styles

I'm currently attempting to incorporate styles into a vuejs single file component. I've successfully achieved this in a node app previously, but now I am working with a python/flask backend (not that it should make a difference). The Vue componen ...

Struggling to transfer information from JavaScript to Python Flask?

I am currently working on a basic configuration where I need to send a string to my Flask application through Ajax, but unfortunately, I am encountering Error code 400: Bad request. Here is the JavaScript code snippet: headers = { 'Content-type&a ...

Struggling with color styling within link_to tags in Rails 4 - having trouble getting inline styling to show up correctly

<%= link_to "Sign In", new_user_session_path, :method => :get, style: "color:white" %> <h3>Read More - <%= link_to 'Article', action: :articles, style: "color: purple" %></h3> <%= link_to 'Click to Read More Abo ...

Ways to adjust the div height to match the span height

.headerDesc { width: 100% + 1px; height: 70px; background-color: #4d2765; margin: 0 -8px; } .headerDesc span { padding: 5px; position: absolute; color: white; font-family: 'Arial', sans-serif; text-al ...

Is there a way to align my two tables next to each other using CSS?

.page { display: grid; grid-template-columns: 1fr 1fr; grid-gap: 20px; } .items { float: left; } .secondItem { vertical-align: text-top; float: right; } .page-header table, th, td { border: 1px solid; display: block; background-color: ...

Using Angular Material for creating tabs with identical content

I am using material with angularjs and have encountered an issue with my two md-tabs. Both tabs have a similar DOM structure, but contain some unique content. Instead of duplicating the common DOM twice, I am looking for an alternative solution. Is it poss ...

Link a YAML file with interfaces in JavaScript

I'm currently learning JavaScript and need to convert a YAML file to an Interface in JavaScript. Here is an example of the YAML file: - provider_name: SEA-AD consortiumn_name: SEA-AD defaults: thumbnail Donors: - id: "https://portal.brain ...

What is the best way to design a webpage that adapts to different screen heights instead of widths?

I'm in the process of designing a basic webpage for a game that will be embedded using an iframe. The game and text should always adjust to fit the height of your screen, so when the window is small, only the game is displayed. The game will be e ...

What is the best way to move the Grid upward when the above content is not visible?

Let me demonstrate what I have been working on. Currently, I am creating a weather application to explore the functionalities of https://material-ui.com/. I am attempting to prototype an animation inspired by Google Flights, which can be seen here: https: ...

"Are you experiencing issues with the Ajax Success function not getting triggered upon returning from the Controller

Can anyone help me with my jQuery code? Here it is: $("#create").click(function(e) { var myModel = { "TribeName": $('#TribeName').val() }; var jsonToPost = JSON.stringify(myModel); $.aja ...

Retrieving information from the controller within the error callback of a jQuery AJAX request in ASP.NET MVC

I've been working with a jQuery ajax script that looks like this: $.ajax({ type: "POST", url: "Main/receive", // the method we are calling contentType: "application/json; charset=utf-8", data: JSON. ...

Embed the PDF stream into an iFrame using JavaScript

In my code, I am utilizing $.post(url, function(data){ // I use data here });. The data I receive from the post request is a PDF stream, with the response content type being application/pdf. My task is to display this PDF within an iframe. The challenge is ...

Upon executing the `npm start` command, the application experiences a crash

When I tried following the steps of the Angular quickstart guide, I encountered some errors after running "npm start". Here are the errors displayed: node_modules/@angular/common/src/directives/ng_class.d.ts(46,34): error TS2304: Cannot find name 'Se ...

Employing various Class Methods based on the chosen target compiler option

Is there a way to instruct TypeScript to utilize different implementations of methods within the same class, based on the specified target option in the tsconfig.json file? I am currently transitioning one of my scripts to TypeScript to streamline managem ...

Ways to adjust the size of the parent element based on the height of a specific element

I am faced with a situation where I need to identify all elements belonging to a specific class and adjust the padding-bottom of their parent div based on the height of the matched element. For example, consider the following structure: <div class=&ap ...

sent a data entry through ajax and performed validation using jquery

Is there a solution to validating the existence of an email value using ajax after validation work is completed? Despite attempting to check for the email value and display an alert if it exists, the form continues to submit regardless. See below for the ...