ngx-pattern
is a small directive you can use to filter allowed input with regular expressions.
Check examples here.
The library has several versions compiled for different angular versions. Make sure to pick the correct one
Angular Version | ngx-pattern Version | Engine Used |
---|---|---|
< 9 | <= 0.2.1 | View Engine |
>= 9 < 12 | ^1.0.0 | View Engine |
>= 12 | ^2.0.0 | Partial-Ivy |
To use ngx-pattern in your project install it via:
-
NPM
npm install ngx-pattern --save
-
Yarn
yarn add ngx-pattern
After installing, include NgxPatternModule
in your application module like:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgxDatatableModule } from 'ngx-pattern';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [NgxPattern, BrowserModule],
bootstrap: [AppComponent]
})
export class AppModule { }
-
You can set up the pattern using a string
<input type="text" [(ngModel)]="lowerCaseText" ngxPattern="[a-z]*"> <input type="text" [(ngModel)]="lowerCaseText" [ngxPattern]="'[a-z]*'">
-
Or a RegEx
numbersOnly = /^[0-9]*$/; ... <input type="text" [ngxPattern]="numbersOnly">
- Partial-Ivy compilation for better compatibility with modern Angular
- Minimum Angular version changed to
12+
- Minimum Angular version changed to
9+
- Update incorrect keydown handling of special keys
- Improved unit tests coverage
- Project switched to
strict
mode
- Support for Angular 12
- Working detection on Android mobile browser
- support for Angular 10 and 11
- updated readme
- string and regex pattern support