[JS] Add the function AFExactMatch
This commit is contained in:
parent
294db228bc
commit
330048ad6b
@ -683,6 +683,14 @@ class AForm {
|
|||||||
eMailValidate(str) {
|
eMailValidate(str) {
|
||||||
return this._emailRegex.test(str);
|
return this._emailRegex.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AFExactMatch(rePatterns, str) {
|
||||||
|
if (rePatterns instanceof RegExp) {
|
||||||
|
return str.match(rePatterns)?.[0] === str || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rePatterns.findIndex(re => str.match(re)?.[0] === str) + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { AForm };
|
export { AForm };
|
||||||
|
@ -1035,7 +1035,7 @@ describe("Scripting", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("ASSimple_Calculate", function () {
|
describe("AFSimple_Calculate", function () {
|
||||||
it("should compute the sum of several fields", async () => {
|
it("should compute the sum of several fields", async () => {
|
||||||
const refIds = [0, 1, 2, 3].map(_ => getId());
|
const refIds = [0, 1, 2, 3].map(_ => getId());
|
||||||
const data = {
|
const data = {
|
||||||
@ -1429,5 +1429,21 @@ describe("Scripting", function () {
|
|||||||
expect(value).toEqual(false);
|
expect(value).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("AFExactMatch", function () {
|
||||||
|
it("should check matching between regexs and a string", async () => {
|
||||||
|
let value = await myeval(`AFExactMatch(/\\d+/, "123")`);
|
||||||
|
expect(value).toEqual(true);
|
||||||
|
|
||||||
|
value = await myeval(`AFExactMatch(/\\d+/, "foo")`);
|
||||||
|
expect(value).toEqual(0);
|
||||||
|
|
||||||
|
value = await myeval(`AFExactMatch([/\\d+/, /[fo]*/], "foo")`);
|
||||||
|
expect(value).toEqual(2);
|
||||||
|
|
||||||
|
value = await myeval(`AFExactMatch([/\\d+/, /[fo]*/], "bar")`);
|
||||||
|
expect(value).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user