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

Get rid of the Modal simply by clicking on the X mark

Objective: The modal should only be closed by clicking the X mark and not by clicking outside of it. Challenge: I am unsure how to resolve this issue when using the syntax code [config]="{backdrop: 'static'}" Additional Information: I am new ...

Is it possible to deactivate the click event on an Angular mat table row?

Within my Angular mat table, I have implemented code that expands a table row when clicked. However, I now need to prevent certain rows from being clickable based on the "element.disable" property. <ng-container matColumnDef="id"> <th mat-hea ...

Embarking on your ABLY journey!

Incorporating https://github.com/ably/ably-js into my project allowed me to utilize typescript effectively. Presently, my code updates the currentBid information in the mongodb document alongside the respective auctionId. The goal is to link the auctionId ...

Navigating an object in TypeScript: the right approach

Curious if there might be a bug in TypeScript? Just seeking clarification on whether my code is incorrect or if there is an actual issue with the language. interface Something { key1: string; key2: number; key3: boolean; } const someObject: S ...

Issue "Value of type '{}' cannot be assigned to parameter of type 'T | (() => T)'" encountered within a React component containing a type parameter

Currently, I am attempting to achieve the following: function SomeComponent<T>({ children }: PropsType) { const [configuration, setConfiguration] = useState<T>({}) } However, I am encountering this issue: The argument of type '{}&apos ...

The Static Interface Binding in TypeScript

I have inquired about how to extend the static functionality of existing objects in JavaScript (using TypeScript). In all examples provided here, I am utilizing Object The code below showcases a polyfill definition for ECMAScript's Object.is function ...

Angular2's counterpart to the angular.version property in AngularJS

If you open the browser's developer console (you can press F12), and type in "angular.version", it will display the version of AngularJS APP that is currently loaded on the page. Is there a similar command for finding out the version of Angular2? ...

What is the best way to retrieve Express app configuration asynchronously?

I am utilizing an Express app developed with the Serverless Framework, which will be hosted via AWS API Gateway and AWS Lambda. The authentication process is handled by Okta, and I am considering storing the necessary secrets in SSM. Currently, I have to f ...

Steps to deactivate a button in an Angular reactive form upon submission

I am working with Angular reactive forms and I need to implement a functionality where the button is disabled and its label changes after it has been clicked or submitted. Any suggestions on how to achieve this? ...

What's the best approach to ensure Angular 2 routing functions smoothly with App Engine when the page is refreshed?

I'm currently working on an Angular 2 application running in the App Engine Standard Environment. I've managed to get it working smoothly by configuring the app.yaml like this for navigating within the app: handlers: - url: /api/.* script: _go ...

Loading an external javascript file dynamically within an Angular component

Currently, I'm in the process of developing an Angular application with Angular 4 and CLI. One of my challenges is integrating the SkyScanner search widget into a specific component. For reference, you can check out this Skyscanner Widget Example. T ...

Struggled to incorporate Typescript function overload's implementation

After reviewing the previous question: Typescript: exclude undefined/null properties from type In my TypeScript project, I attempted to create an overload for a function called request, which can optionally accept a payload. The function is defined by the ...

Restful: Numerous scenarios for a single resource (is it the same API endpoint?)

In this scenario, there are two different approaches to creating a user: If the user is created by an administrator, no password is provided initially. The user must choose a password on the activation page. If the user creates their own account, a passw ...

Issues with binding Angular reactive forms

Exploring the construction of nested reactive forms: https://stackblitz.com/edit/angular-mgrfbj The project structure is as follows: ---create company form (hello.component.ts) --- company details form (company-details.component.ts) --- [ ...

Tips for eliminating unicode characters from Graphql error messages

In my resolver, I have implemented a try and catch block where the catch section is as follows: catch (err: any) { LOG.error("Failed to get location with ID: " + args.id); LOG.error(err); throw new Error(err); ...

Convert checkbox choices to strings stored in an array within an object

I have a intricate object structure JSON{ alpha{ array1[ obj1{}, obj2{} ] } } In addition to array1, I need to include another array: array2 that will only consist of strin ...

Execute the render function of the components that have been passed as

I've been grappling with a challenge lately - figuring out how to invoke a passed component's render function within another function. Let's say I have two functions named A and B: export const A = (value: any) => { return ( <div& ...

Tips for passing a Typescript variable in a jquery callback function

Within an Angular 6 component, I am utilizing a jQuery callback function. This component contains a TypeScript variable, and when a click event occurs on the webpage, the callback function is triggered. However, I am struggling to figure out how to pass th ...

Running AngularJS within an Angular 8 application using ngUpgrade is not supported

Struggling to get my Hybrid Angular application up and running using ngUpgrade according to the documentation. The issue is that no matter what tweaks I make, AngularJS just won't cooperate. When I combine Angular and AngularJS, both applications wor ...

Navigating the way: Directing all TypeScript transpiled files to the build folder

I am currently working on a project using Angular2/Typescript, and I have the tsconfig.js file below: { "compilerOptions": { "module": "commonjs", "moduleResolution": "node", "target": "es5", "sourceMap": true, ...