This package is designed to restrict inputs in Angular **Reactive form** input controls. Based on a **regex** pattern users can restrict the inputs. **This will work for copy pasting as well.**
Usage no npm install needed!
<script type="module">
import ngxInputRegulate from 'https://cdn.skypack.dev/ngx-input-regulate';
</script>
README
NgxInputRegulate
This package is designed to restrict inputs in Angular Reactive form input controls. Based on a regex pattern users can restrict the inputs. This will work for copy pasting as well.
RegEx for common scenarios
1. Integer: ^[0-9 ]*$
2. float: ^[+-]?([0-9]*[.])?[0-9]+$
3. words: ([A-z]*\\s)*$
Any custom regex you might make will be also compatible.
How to Install
Enter the following command in your project root folder (as usual)
npm i ngx-input-regulate
Steps to use
Install the package as show in the above section
Import the module
AppModule.ts
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { ngxInputRegulateModule } from 'ngx-input-regulate';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
ngxInputRegulateModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Define the regex in ngxir-pattern attribute
Add the ngxInputRegulate Directive
AppComponent.html