Skip to content

Commit

Permalink
Merge pull request #15358 from nbrown-ScottLogic/inputTextRegexLimit
Browse files Browse the repository at this point in the history
 Component: KeyFilter #14639 limit input length
  • Loading branch information
cetincakiroglu authored Apr 26, 2024
2 parents bf15195 + 5d07468 commit fa226ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
26 changes: 13 additions & 13 deletions src/app/components/keyfilter/keyfilter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NgModule, Directive, ElementRef, HostListener, Input, forwardRef, Output, EventEmitter, Inject, PLATFORM_ID, Provider, booleanAttribute } from '@angular/core';
import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common';
import { Directive, ElementRef, EventEmitter, HostListener, Inject, Input, NgModule, Output, PLATFORM_ID, Provider, booleanAttribute, forwardRef } from '@angular/core';
import { AbstractControl, NG_VALIDATORS, Validator } from '@angular/forms';
import { DomHandler } from 'primeng/dom';
import { Validator, AbstractControl, NG_VALIDATORS } from '@angular/forms';
import { KeyFilterPattern } from './keyfilter.interface';

export const KEYFILTER_VALIDATOR: Provider = {
Expand Down Expand Up @@ -31,15 +31,15 @@ type Keys = {
};

const DEFAULT_MASKS: Record<KeyFilterPattern, RegExp> = {
pint: /[\d]/,
int: /[\d\-]/,
pnum: /[\d\.]/,
money: /[\d\.\s,]/,
num: /[\d\-\.]/,
hex: /[0-9a-f]/i,
email: /[a-z0-9_\.\-@]/i,
alpha: /[a-z_]/i,
alphanum: /[a-z0-9_]/i
pint: /^[\d]*$/,
int: /^[-]?[\d]*$/,
pnum: /^[\d\.]*$/,
money: /^[\d\.\s,]*$/,
num: /^[-]?[\d\.]*$/,
hex: /^[0-9a-f]*$/i,
email: /^[a-z0-9_\.\-@]*$/i,
alpha: /^[a-z_]*$/i,
alphanum: /^[a-z0-9_]*$/i
};

const KEYS: Keys = {
Expand Down Expand Up @@ -225,8 +225,8 @@ export class KeyFilter implements Validator {
if (!browser.mozilla && (this.isSpecialKey(e) || !cc)) {
return;
}

ok = (<RegExp>this.regex).test(cc);
let val = this.el.nativeElement.value + cc;
ok = (<RegExp>this.regex).test(val);

if (!ok) {
e.preventDefault();
Expand Down
7 changes: 3 additions & 4 deletions src/app/showcase/doc/keyfilter/regexdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { Code } from '../../domain/code';
`
})
export class RegexDoc {
blockSpace: RegExp = /[^\s]/;

blockSpace: RegExp = /^[^\s]+$/;
blockChars: RegExp = /^[^<>*!]+$/;

code: Code = {
Expand All @@ -49,8 +48,8 @@ import { Component } from '@angular/core';
templateUrl: './key-filter-reg-exp-demo.html'
})
export class KeyFilterRegExpDemo {
blockSpace: RegExp = /[^\s]/;
blockSpace: RegExp = /[^\s]/;
blockChars: RegExp = /^[^<>*!]+$/;
}`
};
Expand Down

0 comments on commit fa226ec

Please sign in to comment.