Skip to content

Commit

Permalink
Introduce insensitive property into RegexValidator #7620
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jan 4, 2024
1 parent 034fe2e commit ffd4bf2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,14 @@ export class RegexValidator extends SurveyValidator {
public set regex(val: string) {
this.setPropertyValue("regex", val);
}
public get insensitive(): boolean {
return this.getPropertyValue("insensitive");
}
public set insensitive(val: boolean) {
this.setPropertyValue("insensitive", val);
}
private createRegExp(): RegExp {
let pattern = this.regex;
let flags = "";
if(pattern.endsWith("/i")) {
pattern = pattern.substring(0, pattern.length - 2);
flags = "i";
}
return new RegExp(pattern, flags);
return new RegExp(this.regex, this.insensitive ? "i" : "");
}
}
/**
Expand Down Expand Up @@ -525,7 +525,7 @@ Serializer.addClass(
);
Serializer.addClass(
"regexvalidator",
["regex"],
["regex", { name: "insensitive:boolean", visible: false }],
function() {
return new RegexValidator();
},
Expand Down
3 changes: 2 additions & 1 deletion tests/surveyvalidatortests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ QUnit.test("Regex number validator, Bug#1775", function(assert) {
assert.equal(validator.validate(null), null, "Parse correctly null");
});
QUnit.test("Regex case insensitive, Bug#7620", function(assert) {
var validator = new RegexValidator("[email protected]/i");
const validator = new RegexValidator("[email protected]");
validator.insensitive = true;
validator.text = "Error";
assert.equal(validator.validate("abc").error.text, "Error", "#1");
assert.equal(validator.validate("[email protected]").error.text, "Error", "#2");
Expand Down

0 comments on commit ffd4bf2

Please sign in to comment.