An issue with the validation service has been identified, specifically concerning the default value of null in

Using Angular 10 and Password Validator Service

 static password(control: AbstractControl) {

        // {6,100}           - Check if password is between 6 and 100 characters
        // (?=.*[0-9])       - Ensure at least one number is present in the string
        if (control.value.match(/^(?=.*[0-9])[a-zA-Z0-9!@#$%^&*]{6,100}$/)) {
          return null;
        } else {
          return { invalidPassword: true };
        }
      }

Working Code

this.loginForm = this.formBuilder.group({
      username:'' ,
      password: ['', [ValidationService.password]]
    });

Not working Code :

  this.loginForm = this.formBuilder.group({
          username:'' ,
          password: [null, [ValidationService.password]]
        });

The issue occurred after using null instead of an empty string. Please advise on how to fix it.

https://i.stack.imgur.com/9BHcH.png

EDIT :

HTML

          <div class="input-group mb-4">
            <div class="input-group-prepend">
              <span class="input-group-text"><i class="icon-lock"></i></span>
            </div>
            <input type="password" class="form-control" placeholder="Password" autocomplete="current-password"
              formControlName="password" required>
          </div>
          <div class="form-group row">
            <div class="col-md-9">
           
              <ar-validation-message [control]="loginForm.controls.password"></ar-validation-message>
            </div>
          </div>

Answer №1

insert the safe navigation operator ?. at this point

if (control.value?.match(...

this specific code allows for null values to pass without causing an error

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

connect the validation of forms to different components

I am currently working on components to facilitate the user addition process. Below is an example of my form component: createForm(): void { this.courseAddForm = this.formBuilder.group({ name: ['', [ Validators.required, ...

Ways to retrieve every item in an array

I'm experiencing difficulty accessing the array of each object. Please review the response structure below. { "status": "1", "status_text": "Success", "current_page": 1, "next_page": "0", "previous_page": "0", "to ...

Is it possible to manually activate a dropdown event using pure JavaScript?

I am attempting to manually trigger a dropdown event using JavaScript. Below is the function where I am trying to achieve this. I have successfully halted the initial event that occurs and now I need to initiate a dropdown event. stopNavigationTriggerDrop ...

What could be causing my Ionic/Firebase subscription to be triggered three times?

I'm having an issue with my code where it seems to be executed 3 times and I can't figure out why. advertenciaMantto() { this.afs.doc('Core/Programador').valueChanges().subscribe(async (data) => { await this.afs.firestore.doc(` ...

Issue encountered while declaring a variable as a function in TSX

Being new to TS, I encountered an interesting issue. The first code snippet worked without any errors: interface Props { active: boolean error: any // unknown input: any // unknown onActivate: Function onKeyUp: Function onSelect: Function onU ...

What exactly does "context" refer to in the context of TypeScript and React when using getServerSideProps?

As a beginner in coding, I have a question regarding a specific syntax I recently encountered. I am confused about this particular line of code and couldn't find any helpful explanations online: export async function getServerSideProps(context: GetSer ...

Issues with incorrect source path in Typescript, Gulp, and Sourcemaps configuration

In my nodejs app, the folder structure is as follows: project |-- src/ | |-- controllers/ | | |`-- authorize-controller.ts | |`-- index.ts |--dist/ | |--controllers/ | | |`-- authorize-controller.js | | |`-- authorize-controller.js.map | ...

Cross-Origin Resource Sharing problem in HttpResponse Activity

Currently, I am utilizing the Elsa-Core - AspnetCore Monolith Dashboard example. Workflow: The issue arises in the HttpReponse Activity, while the HttpEndpoint functions correctly. I am encountering an error on the client side which I am unable to captu ...

Handling routerLink exceptions in Angular 2, 4, and 5

In my app, I am working on catching routing exceptions. There are three ways in which a user can navigate: If the user types the address directly - this can be caught easily by using { path: '**', redirectTo: 'errorPage'} in the route ...

Having Issues with CDK Virtual Scrolling in Angular Material Table

Dealing with an angular material table that contains millions of records can be quite challenging. I have implemented pagination with various options such as 10, 25, 50, 100, 500, and 1000 items per page. However, when selecting the option for 1000 or all ...

Is it possible for a ngrx signal feature store to retrieve the state of the store that it is consuming?

I am interested in creating a feature store that can receive input or reference a state from the store which interacts with or consumes the store, such as the parent of the ngrx signal feature store. For instance, imagine I have a store named "withCounter ...

What is the best way to include 'SCSS' in the 'rollup' project that I have developed?

I am embarking on the creation of a React UI library and have chosen 'rollup' as my build tool. To enhance the project, I plan to incorporate TypeScript and utilize SCSS for styling. How can I implement SCSS within this setup? You can find the s ...

One way to change the cursor CSS property is by dynamically altering it based on scrolling behavior. This involves modifying the cursor property when scrolling

I'm attempting to adjust the cursor property within an Angular function. The issue I'm facing is that when I begin scrolling the webpage, the cursor changes to a pointer, but when I stop scrolling, it remains as a pointer. I've attempted to ...

What is the simplest way to incorporate Vue with Typescript, without the need for a complex build setup?

I've been spending the last couple of days experimenting with my basic ASP.NET Core website set up for Typescript 2.9, but unfortunately, I haven't made much progress. My main goal is to keep the front-end simple, with just single Vue apps on eac ...

Creating a Prisma schema with a complex nested structure and incorporating an array of strings for a specific property

I'm trying to create a detailed Prisma schema for a product database that includes nested properties and an array of strings for image content. The structure I'm aiming for looks like this: interface Product { id: number; name: string; ...

Transform TypeScript class into an object

Is there a way to transfer all values from one typescript class, Class A, to another matching class, Class B? Could there be a method to extract all properties of Class A as an object? ...

Running lint-staged on an Angular monorepo

I am facing challenges while setting up lint-staged in my Angular monorepo workspace. Despite multiple attempts, I have been unsuccessful in making it work properly. When the command ng lint --files is executed with a changed file, an error stating that *f ...

Having trouble with the image source in Angular?

I've encountered an issue with the img src in my Angular project. Upon some investigation, I relocated my images to the assets folder, which resolved the error 404 message. While uploading my background image, everything worked smoothly. However, when ...

Issue with Socket.io: Data not received by the last user who connected

I have developed a Node.js and Express application with real-time drawing functionality on canvas using socket.io version 1.7.2. Users are divided into separate socket rooms to enable multiple teams to draw independently. However, there is an issue where t ...

Filtering data on objects in Angular can be achieved by utilizing the built-in

Retrieving data from the backend using this function: private fetchData(): void { this.dataService.fetchData().pipe( tap((response: any) => { this.persons = response.results; this.familyMembersTrue = this.persons.filter(x =&g ...