Skip to content

Commit

Permalink
Add case sensitive config option to regex validation trigger function
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-bulgaris-qcif committed Dec 19, 2022
1 parent 35c06d2 commit 48cf3e7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions typescript/api/services/TriggerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ export module Services {
}
}

private validateRegex(data, regexPattern, fieldLanguageCode, errorMessageCode) {
let re = new RegExp(regexPattern,'i');
private validateRegex(data, regexPattern, fieldLanguageCode, errorMessageCode, caseSensitive) {
let re;
if(caseSensitive) {
re = new RegExp(regexPattern);
} else {
re = new RegExp(regexPattern,'i');
}
sails.log.verbose('validateFieldUsingRegex data.toString() '+data.toString());
let reTest = re.test(data.toString());
sails.log.error('validateFieldUsingRegex reTest '+reTest);
sails.log.verbose('validateFieldUsingRegex caseSensitive '+caseSensitive+' reTest '+reTest);
if(!reTest) {
let customError: RBValidationError;
if(!_.isUndefined(fieldLanguageCode)) {
Expand All @@ -155,6 +161,7 @@ export module Services {
//Set false by default if not present this option will remove leading and trailing spaces from a none array value
//then it will modify the value in the record if the the regex validation is passed therefore handle with care
let trimLeadingAndTrailingSpacesBeforeValidation = _.get(options,'trimLeadingAndTrailingSpacesBeforeValidation') || false;
let caseSensitive = _.get(options,'caseSensitive') || true;

let data = _.get(record, fieldDBName);

Expand All @@ -168,7 +175,7 @@ export module Services {

if(!_.isUndefined(objField) && objField != null && objField != '' && !_.isUndefined(regexPattern) && !_.isUndefined(errorMessageCode) ) {

this.validateRegex(objField, regexPattern, fieldLanguageCode, errorMessageCode);
this.validateRegex(objField, regexPattern, fieldLanguageCode, errorMessageCode, caseSensitive);
}
}

Expand All @@ -183,7 +190,7 @@ export module Services {
data = trimData;
}

this.validateRegex(data, regexPattern, fieldLanguageCode, errorMessageCode);
this.validateRegex(data, regexPattern, fieldLanguageCode, errorMessageCode, caseSensitive);

if(trimLeadingAndTrailingSpacesBeforeValidation) {
_.set(record,fieldDBName,data);
Expand Down

0 comments on commit 48cf3e7

Please sign in to comment.