Generates regular expression according to passed parameters.
npm i gen-regex-angular
Step 1
Import module in your app.component.ts
file
import { GenRegexAngular } from 'gen-regex-angular';
Step 2
After import, create instance of imported module inside constructor
constructor(private genRegexAngular: GenRegexAngular) {}
Step 3
Now, you are all set to use this module in your angular project.
To use the particular regex pattern for formcontrol validation. Suppose we have to validate formcontrol "email". The code will look like
email = new FormControl('', [Validators.pattern(this.genRegexAngular.regexpattern('mail'))])
above code is similar to
email = new FormControl('', [Validators.pattern('^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,10}$')])
You can find the parameters to use in function in below table.
Parameter | Usage | Output |
---|---|---|
regexpattern('mail') | ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,10}$ | |
pan | regexpattern('pan') | ^[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}$ |
aadhar | regexpattern('aadhar') | ^[2-9]{1}[0-9]{3}[0-9]{4}[0-9]{4}$ |
gst | regexpattern('gst') | ^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$ |
Currently, We focussed on these 4 primary patterns which are widely used in India. We are working on improving this module.