Skip to content

Commit bf5e456

Browse files
Fix for passing dot as splitcharacter to RegExp constructor
1 parent 7eb46aa commit bf5e456

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/TextInputMask.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function detectCharacter(mask: string): string {
77
return c || ''
88
}
99

10+
function escapeForRegExp(value: string): string {
11+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
12+
}
13+
1014
function TextInputWithMask(
1115
{
1216
onChangeText,
@@ -40,7 +44,7 @@ function TextInputWithMask(
4044
)
4145
const replaceValue = format.match(/\W/)
4246
const replace = `$1${splitCharacter}$2${splitCharacter}$3$4`.replace(
43-
new RegExp(splitCharacter, 'g'),
47+
new RegExp(escapeForRegExp(splitCharacter), 'g'),
4448
(replaceValue ?? '') as string
4549
)
4650

0 commit comments

Comments
 (0)