From 82b6b605c8cf4c6561ef60a115c8e22eb18b1ce2 Mon Sep 17 00:00:00 2001 From: Nathanael Brown Date: Thu, 25 Apr 2024 10:46:24 +0100 Subject: [PATCH 1/2] Changed keyfilter to test the entire string in a text box to ensure the whole string passes the ReGeX rather than just the most recently entered character. Also updated preset regexes to work in accordance with these changes --- src/app/components/keyfilter/keyfilter.ts | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/app/components/keyfilter/keyfilter.ts b/src/app/components/keyfilter/keyfilter.ts index cd9d2f71d55..3870746e09e 100755 --- a/src/app/components/keyfilter/keyfilter.ts +++ b/src/app/components/keyfilter/keyfilter.ts @@ -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 = { @@ -31,15 +31,15 @@ type Keys = { }; const DEFAULT_MASKS: Record = { - 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 = { @@ -225,8 +225,8 @@ export class KeyFilter implements Validator { if (!browser.mozilla && (this.isSpecialKey(e) || !cc)) { return; } - - ok = (this.regex).test(cc); + let val = this.el.nativeElement.value + cc; + ok = (this.regex).test(val); if (!ok) { e.preventDefault(); From 5d07468311967c2cfef80ead3d17f00ccde71838 Mon Sep 17 00:00:00 2001 From: Nathanael Brown Date: Thu, 25 Apr 2024 11:03:08 +0100 Subject: [PATCH 2/2] Fixed blockSpace regex so that it works now with altered keyfilter --- src/app/showcase/doc/keyfilter/regexdoc.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/app/showcase/doc/keyfilter/regexdoc.ts b/src/app/showcase/doc/keyfilter/regexdoc.ts index 79d4ba028f5..138dd5d5a18 100644 --- a/src/app/showcase/doc/keyfilter/regexdoc.ts +++ b/src/app/showcase/doc/keyfilter/regexdoc.ts @@ -21,8 +21,7 @@ import { Code } from '../../domain/code'; ` }) export class RegexDoc { - blockSpace: RegExp = /[^\s]/; - + blockSpace: RegExp = /^[^\s]+$/; blockChars: RegExp = /^[^<>*!]+$/; code: Code = { @@ -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 = /^[^<>*!]+$/; }` };