Skip to content

Commit

Permalink
simple fix to allow numeric fields to be checked against a pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
rekliner committed Jan 18, 2023
1 parent 6d44fcd commit 59c5179
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/logic/validateField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ export default async <T extends FieldValues>(
}
}

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,
Expand Down

0 comments on commit 59c5179

Please sign in to comment.