Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/core/src/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ describe("builtInValidationFunctions", () => {
expect(builtInValidationFunctions.numeric(NaN)).toBe(false);
expect(builtInValidationFunctions.numeric(null)).toBe(false);
});

it("fails for strings with trailing non-numeric characters", () => {
expect(builtInValidationFunctions.numeric("123abc")).toBe(false);
expect(builtInValidationFunctions.numeric("99bottles")).toBe(false);
});

it("fails for empty and whitespace-only strings", () => {
expect(builtInValidationFunctions.numeric("")).toBe(false);
expect(builtInValidationFunctions.numeric(" ")).toBe(false);
});
});

describe("url", () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ export const builtInValidationFunctions: Record<string, ValidationFunction> = {
*/
numeric: (value: unknown) => {
if (typeof value === "number") return !isNaN(value);
if (typeof value === "string") return !isNaN(parseFloat(value));
if (typeof value === "string") {
return value.trim() !== "" && !isNaN(Number(value));
}
return false;
},

Expand Down
Loading