Skip to content

Commit 26196f6

Browse files
authored
Merge pull request tttstudios#58 from JoelBesada/fix-issue-12
Fix onCodeFilled not being called when extracting code from clipboard
2 parents f93e847 + fcaf590 commit 26196f6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@ export default class OTPInputView extends Component {
104104
}
105105

106106
checkPinCodeFromClipBoard = () => {
107-
const { pinCount } = this.props
107+
const { pinCount, onCodeFilled } = this.props
108+
const regexp = new RegExp(`^\\d{${pinCount}}$`)
108109
Clipboard.getString().then(code => {
109-
if (this.hasCheckedClipBoard && code.length === pinCount && (this.clipBoardCode !== code)) {
110+
if (this.hasCheckedClipBoard && regexp.test(code) && (this.clipBoardCode !== code)) {
110111
this.setState({
111112
digits: code.split(""),
112113
}, () => {
113114
this.blurAllFields()
114115
this.notifyCodeChanged()
116+
onCodeFilled && onCodeFilled(code)
115117
})
116118
}
117119
this.clipBoardCode = code

0 commit comments

Comments
 (0)