Validation of passwords containing special characters in Angular2

I am working on setting up password validation requirements to ensure the field contains:

Both uppercase letters, lowercase letters, numbers and special characters

This is my current progress:

passwordValueValidator(control) {
  if (control.value != undefined) {
    if (!control.value.match(/^(?=.*[0-9])[a-zA-Z0-9!@#$%^&*]{6,100}$/)) {
      return { 'invalidPassword': true };
    }
    else{
      // Here I need to include a check for special characters as well
    }
  }
}

The existing code covers only letters and numbers combinations. What additional steps are needed to verify if special characters have been entered by the user?

Special characters should include: !@#$%^&*()_+ (input via shift key + number keys 0-10)

Answer №1

Give this pattern a shot:

/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{6,100})/

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

Resolving TS2304 error using Webpack 2 and Angular 2

I have been closely following the angular documentation regarding webpack 2 integration with angular 2. My code can be found on GitHub here, and it is configured using the webpack.dev.js setup. When attempting to run the development build using npm start ...

Configuring SSL for an AWS Mean Stack deployed on an EC2 instance with ngInx hosting

Currently in the process of setting up SSL/https for my website, following steps from various sources but encountering some issues. Seeking guidance. Here are the steps I have taken so far: Hosted my MEAN stack website on EC2 in AWS. Both UI and Bac ...

Typescript is unable to access the global variables of Node.js

After using Typescript 1.8 with typings, I made the decision to upgrade to typescript 2.8 with @types. When I downloaded @types/node, my console started showing errors: error TS2304: Cannot find name 'require'. The project structure is as foll ...

Avoiding data type conversion in JavaScript/TypeScript

Currently delving into the world of JavaScript, I come from a background of working with statically typed languages. Naturally, I opted to dive into TypeScript instead of starting directly with JS. While TypeScript is great and addresses many issues presen ...

Angular7 & Bootstrap4: Creating a collapsible navigation bar

Currently, I am working on creating a navbar with a collapsible animation that functions properly on mobile screen sizes. I have been following a tutorial which has guided me in the right direction: . Although I have successfully implemented the functiona ...

Troubleshooting problems with routing for an Angular 5 single page application when serving it from a Lumen 5.2 controller

I am facing an issue with serving an Angular SPA from a single routed Lumen endpoint. While the initial boot of the Angular application works fine when navigating directly to the endpoint, loading any child route of the Angular SPA does not work properly. ...

Creating a python regex pattern that can accurately identify all Unicode letters

Having trouble finding a solution in Python for recognizing unicode letters without confusing punctuation or diacritics? I aim to label all ASCII and unicode letters as "A" and numbers [1-9] as 9. Here's my current function: def multiple_replace(myS ...

Tips for utilizing intellisense from monaco.d.ts

Is there a way for me to incorporate monaco.d.ts in order to utilize intellisense with the monaco-editor package? I've recently integrated this package into a JavaScript project and everything is functioning properly. However, as I transition to Type ...

What is the procedure for implementing a RoleGuard in Angular 6?

Is there a way to retrieve the user role from the token? I've managed to fetch the token using the decoding feature of angular2-jwt, but when I try to apply it for accessing the admin route, it returns a value of false. Upon checking with console.lo ...

The Angular Validator Pattern may be effective in HTML, but it seems to encounter limitations when

In the world of HTML, Regular Expressions can be quite useful as demonstrated in the example below: <input type="text" formControlName="mgmtIP" class="input-text" pattern="([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]& ...

Utilizing the validator in Vue with the setup script, TypeScript, and the composition API

While working on some code from a tutorial, I came across the challenge of implementing a validator in a similar fashion to the example provided. My task involves utilizing the script setup, typescript, and the composition API. props: { image: { ...

I just finished setting up Angular by running the npm install -g @angular/cli command. However, when I tried to verify if Angular was successfully installed by using the ng -v

logAfter installing Angular using the npm install -g @angular/cli command, I encountered an issue when trying to check if it was successfully installed by running the ng-v command. It kept showing 'no command found'. I even added C:\Users&bs ...

The child component stays consistent across all Angular routing configurations

Currently diving into Angular routing, I've added two routerLinks to the parent component. It appears that routing is set up correctly, but for some reason the page remains unchanged. Parent Child const childrenRoutes: Routes =[ {path: 'overvi ...

The issue with hiding the Angular PrimeNG megamenu despite setting the visibility to false

Need help with Angular PrimeNG megamenu visibility issue. <p-megaMenu [model]="menuItems"></p-megaMenu> this.menuItems = [ { label: 'Home', items: null, routerLink: [''] }, ...

Incorporating yarn into your Vue3 project with Typescript

I'm attempting to implement a solution from https://yarnpkg.com/package/vue-disable-autocomplete that disables autocomplete in my Vue3 project. After running yarn add vue-disable-autocomplete, I included the following code: import DisableAutocomplete ...

What is the best way to bring in a file or subfolder from a folder that has been

Currently, I am facing a situation where I need to specify to TSC in the tsconfig file that I want to include specific files or subfolders from a folder while ignoring others. How can I achieve this? For instance: /. |-folder 1 |->file2.ts |-& ...

Rotating images on a canvas

We're currently implementing Ionic and Angular in our project. One issue we are facing is regarding image rotation on canvas. When we click on an image, the rotation works perfectly if it's a jpg file. However, when we pass a base64 image, the r ...

Using Django to create URL regular expressions for random string IDs

When constructing URLs, I need to include IDs that follow a specific pattern. The ID should consist of [int]_ followed by a random string of 22 characters. The characters can be letters or numbers but must not contain any URL unsafe symbols such as /, +, ...

Is there a way to assign a null value to an empty material UI text field when submitting the form, rather than an empty string?

One issue I am facing is that the default value of the text field is zero, but when I submit the form, the value of the text field becomes an empty string instead. This is not the intended behavior as I want the value to remain zero in the end. How can I r ...

Angular 2 observables not functioning properly with web API

I have been encountering issues while trying to access the WEB API using the http.get method. The service I am implementing utilizes observables, but it does not seem to be functioning properly. There are no calls being made to the server and no error me ...