From 59c517968326fb03a02ce1c182dddf976616c14e Mon Sep 17 00:00:00 2001 From: Rekliner Date: Tue, 17 Jan 2023 22:28:02 -0600 Subject: [PATCH] simple fix to allow numeric fields to be checked against a pattern --- package.json | 2 +- src/logic/validateField.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a0295b83307..1ce993be311 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-hook-form", "description": "Performant, flexible and extensible forms library for React Hooks", - "version": "7.42.1", + "version": "7.42.2", "main": "dist/index.cjs.js", "module": "dist/index.esm.mjs", "umd:main": "dist/index.umd.js", diff --git a/src/logic/validateField.ts b/src/logic/validateField.ts index 01f4bc8981b..820bd0b978b 100644 --- a/src/logic/validateField.ts +++ b/src/logic/validateField.ts @@ -204,10 +204,10 @@ export default async ( } } - if (pattern && !isEmpty && isString(inputValue)) { + if (pattern && !isEmpty && (isString(inputValue) || valueAsNumber)) { const { value: patternValue, message } = getValueAndMessage(pattern); - if (isRegex(patternValue) && !inputValue.match(patternValue)) { + if (isRegex(patternValue) && !String(inputValue).match(patternValue)) { error[name] = { type: INPUT_VALIDATION_RULES.pattern, message,