Skip to content

Commit

Permalink
fix(scanner): only accept single digit characters
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen committed Oct 9, 2024
1 parent bb2022d commit 9f96863
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/app/bl-common/blc-scanner/blc-scanner.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ export class BlcScannerDirective {
if (event.key === "Enter") {
this.processScannerString();
this.scannerString = "";
} else {
if (this.isAlphaNumeric(event.key)) {
this.scannerString += event.key;
}
} else if (event.key.length === 1) {
this.scannerString += event.key;
}

if (this.scannerString.length > 13) {
Expand All @@ -72,7 +70,8 @@ export class BlcScannerDirective {
this._blcScannerService.scanBlid(this.scannerString);
} else if (
this.scannerString.length > 9 &&
this.scannerString.length < 14
this.scannerString.length < 14 &&
this.isNumeric(this.scannerString)
) {
this._blcScannerService.scanIsbn(this.scannerString);
} else {
Expand All @@ -86,7 +85,7 @@ export class BlcScannerDirective {
}
}

private isAlphaNumeric(key: string) {
return !(!key || key === "Shift");
private isNumeric(value) {
return /^-?\d+$/.test(value);
}
}

0 comments on commit 9f96863

Please sign in to comment.