Skip to content

Commit 4790068

Browse files
committed
feat(package): added support of custom regex validation #147 # 155
1 parent 3ecbca6 commit 4790068

File tree

10 files changed

+11551
-143
lines changed

10 files changed

+11551
-143
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export class OtherModule {
179179
|:-------------------|:--------:|:------:|:------------:|:-------------------------------------------------------------------------------------------------|
180180
| password | `Input() ` | string | - | the password to calculate its strength
181181
| validators | `Input() ` | Criteria[] | see inside the class ;) | custom form validator used to validate the password
182+
| customValidator | `Input() ` | RegExp | - | custom regex validator
182183
| externalError | `Input() ` | boolean | `false` | used to change the color of the password to warn if an external error occurs
183184
| enableLengthRule | `Input() ` | boolean | true | whether to validate the length of the password
184185
| enableLowerCaseLetterRule | `Input() ` | boolean | true | whether a lowercase letter is optional
@@ -199,6 +200,7 @@ export class OtherModule {
199200
| upperCaseCriteriaMsg | `Input() ` | `string` | contains at least one upper character | an appropriate msg for the upper case %
200201
| digitsCriteriaMsg | `Input() ` | `string` | contains at least one digit character | an appropriate msg for the digit case %
201202
| specialCharsCriteriaMsg | `Input() ` | `string` | contains at least one special character | an appropriate msg for the special case %
203+
| customCharsCriteriaMsg | `Input() ` | `string` | contains at least one custom character | an appropriate msg for the custom validator case %
202204
| minCharsCriteriaMsg | `Input() ` | `string` | contains at least ${this.passwordComponent.min} characters | an appropriate msg for the minimum number of chars %
203205

204206

@@ -365,6 +367,48 @@ this will looks like -->
365367

366368
---
367369

370+
#### custom regex validation
371+
372+
please consider to use the `customValidator` input (see below)
373+
374+
```html
375+
<mat-slide-toggle #toggle>Show Password Details</mat-slide-toggle>
376+
377+
<mat-form-field appearance="outline" style="width: 100%" [color]="passwordComponent.color">
378+
<mat-label>Password</mat-label>
379+
<mat-pass-toggle-visibility #toggleVisbility matSuffix></mat-pass-toggle-visibility>
380+
<input matInput #password
381+
[type]="toggleVisbility.type"
382+
placeholder="Password">
383+
<mat-hint align="end" aria-live="polite">
384+
{{password.value.length}} / {{passwordComponent.max}}
385+
</mat-hint>
386+
</mat-form-field>
387+
388+
389+
<mat-password-strength #passwordComponent
390+
(onStrengthChanged)="onStrengthChanged($event)"
391+
[password]="password.value"
392+
[customValidator]="pattern">
393+
</mat-password-strength>
394+
395+
<mat-password-strength-info
396+
*ngIf="toggle.checked"
397+
[passwordComponent]="passwordComponent6"
398+
customCharsCriteriaMsg="1 german special chars is required"
399+
[enableScoreInfo]="true">
400+
</mat-password-strength-info>
401+
402+
```
403+
404+
405+
406+
```ts
407+
pattern = new RegExp(/^(?=.*?[äöüÄÖÜß])/);
408+
```
409+
410+
411+
368412
#### Supporting custom messages and ngx-translate for the info component please check the example demo [here](https://angular-material-extensions.github.io/password-strength/examples/mat-password-strength-info)
369413

370414
<p align="center">

0 commit comments

Comments
 (0)