Delete the span element if the password requirements are satisfied

I am implementing password rules using span elements. I aim to dynamically remove each span that displays a rule once the input conditions are met. Currently, I have succeeded in removing the span related to the minimum length requirement but I am unsure how to remove the others.

Below is my HTML code:

<input name="user_password" ng-minlength="8" ng-model="passForm.user_password1" id="user_password" type="password">
<label class="left-align" for="user_password">Password*</label>
</div>
<div class="input-field col s12">
<input name="user_password_confirm" ng-model="passForm.user_password2" id="user_password_confirm"
type="password" class="validate">
<span style="color:red" ng-if="passForm.user_password2 && passForm.user_password1 != passForm.user_password2">
<ul>Confirm password do not match.</ul>
</span>
<span style="color:red; display: block !important;">
Password should adhere to the following rules:<br>
</span>
<span style="color:red; display: block !important;" ng-if="!passForm.user_password1 || passForm.user_password1.$error.minlength">
- minimum 8 characters<br>
</span>    
<span style="color:red; display: block !important">
- at least 1 uppercase character<br>
- at least 1 lowercase character<br>
- at least 1 digit<br>
- at least 1 special character [@$!#%*?&.]<br>
</span>

And here's my controller:

$scope.changeUserPassword = function(){
var eFlag = false;
$scope.errors = {};
var rePassword = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&#.])[A-Za-z\d$@$!%*?&#.]{8,}/;
if ($scope.passForm.user_password1 && rePassword.test($scope.passForm.user_password1) == false) {
swal('Error!', "Please enter a password that follows the specified rules",'error');
eFlag = true;
}

Answer №1

To simplify, isolate each rule individually and delete the span tags as needed.
In other words

var rule1 = /^[^A-Z]*[A-Z]/;
if (rule1.test($scope.passForm.user_password1)) {
    // take out the uppercase span tag here
});

var rule2 = /^[^a-z]*[a-z]/;
if (rule2.test($scope.passForm.user_password1)) {
    // remove the lowercase span tag here
});

Continue this pattern for each rule. Store rules in an array and iterate through them.

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

Overcoming Troublesome Login Input Box in Web

In an effort to streamline tasks in our office, I am working on automating certain processes. Specifically, this program is designed to log into our insurance company's website and extract information for payroll purposes. Below is the code snippet th ...

Utilizing internal PDF links in a Microsoft UWP application

In the process of developing a UWP app using javascript, I have created a list of links that are connected to PDF files stored locally in the app. The ultimate goal is to offer a collection of hands-free documentation for the Hololens (Windows AR) device. ...

Show the error message from passport.js authentication in the user interface

I am currently working on a new project with Sails.js and using Passport.js for user authentication. Despite having the basic authentication set up, I am struggling to display error messages in the login view when incorrect credentials are entered. I have ...

Locating characters within a string using JavaScript

Currently, I am enrolled in JavaScript classes and have come across a challenging question. In this scenario, the task is to create a function named countLetters. This function will take two parameters: 1) sentence - this parameter should be of type stri ...

I am interested in utilizing Selenium to interact with a hyperlink within an HTML table

I am currently using the code snippet below to fetch data from the HTML structure provided: //findTables(driver); WebElement content = driver.findElement(By.id("tblTaskForms")); List<WebElement> elements = content.findElements(By.className("form-nam ...

When editing html files in Vim, the javascript indent filetype plugin is sourced unexpectedly

After experimenting with my vim settings, I noticed an unexpected behavior. When editing html files in vim, both the indent/javascript.vim and indent/html.vim filetype plugins seem to be sourced simultaneously. Is this intentional or a bug? How can I ensur ...

Leveraging the power of JavaScript functions together with the asp:Timer component

<p><b> Progress: <asp:Label ID="progressPercentageLabel" runat="server"></asp:Label>%</b></p> <script> function updateBar() { var bar = document.getElementById("CompletionBar"); ...

Accessing and playing audio files from Amazon S3 within Python code

I am attempting to directly read an audio file from S3 using Python. Initially, I record the audio with the following blob settings: blob = new Blob(audioChunks,{type: 'audio/wav'}); Then, I upload this file to S3 using Django: req=request.POST ...

Tips on handling a nested HTML hyperlink in Selenium using Python with IE11

Can anyone assist me in resolving the issue of clicking on a hyperlink within an HTML page that contains nested HTML elements up to 4 levels deep? I have attempted various methods using XPATH, but they do not seem to work during runtime. I am utilizing Sel ...

Designing a dropdown menu within displaytag

I am currently utilizing displaytag to present tabular data, but I aspire to design a user interface akin to "kayak.com" where clicking on a row reveals additional details without refreshing the page. Here is an example scenario before clicking the Detail ...

Is it possible to include array elements in a dropdown menu using React?

Imagine you have an array called const places = [" a1", "a2", "a3"]; and <FormControl variant="outlined" className={classes.formControl}> <InputLabel id="dropdown_label">Testing</InputL ...

Generating a list of objects from an array of strings

I am currently facing an issue in my code and I could use some help with it. Below are the details: I have a array of string values containing MAC addresses and constant min & max values. My goal is to map over these MAC values and create an array of obje ...

Ways to determine the count of selected checkboxes in React.js?

Recently, I delved into learning React. For one of my beginner projects, I decided to create a "life checklist" using Functional Components as the foundation. Just a heads up: I've structured data.js as an array of objects containing "action", "emoj ...

Enhance your SVG image in D3 by incorporating a drop-shadow effect

Trying to apply a drop-shadow effect to an SVG image using D3. Check out my code below and see the example block here: var imgurl = 'http://www.logo-designer.co/wp-content/uploads/2015/08/2015-Penn-State-University-logo-design-4.png'; var mar ...

Obtain SVG icons seamlessly in Next.js

My goal was to dynamically retrieve SVG icons, and I discovered a method to achieve this. However, it seems like I have made some errors along the way. Can you point out where I am going wrong? Icon.js import React from "react"; import { ReactCo ...

I wonder where the file from the HTML form download has originated

Recently, I've been experimenting with the developer tools in Chrome to observe the behavior of websites at different moments. It has proven useful in automating certain tasks that I regularly perform. Currently, my focus is on automating the process ...

Scroll effortlessly with wrapping divs

Hey there! I've been experimenting with the Smooth Div Scroll plugin which you can find on their website here: The implementation is pretty simple. I'm using the touch example, but with a twist - instead of images, I am using Divs to scroll thro ...

Neglecting to send a socket signal while assigning a variable to a socket message

In my client-side script, I am using the following snippet: socket.on('bla', function(data) { if (data == ID) { console.log('I don't understand what's happening here.'); } }) socket.on(ID, function(data) { ...

Steps to implement jQuery after executing the command "npm install jquery"

Greetings! I recently utilized npm install jquery to add jQuery to my project. However, I noticed that it was downloaded into node_modules\jquery along with some unnecessary files. My goal is to only move node_modules\jquery\dist\jquer ...

"Successful implementation of Ajax function in local environment but encountering issues when running online

I am facing an issue with my AJAX function. It works perfectly fine on my local server but does not return anything when I move it to my online server. Below is the code snippet: This is the part of the page where I call the showEspece() function: echo ...