Created
May 17, 2020 18:01
-
-
Save jsmanifest/0a44a52e29986cd4538f156bba213ea6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isDigits(value) { | |
return /^\d+$/.test(value) | |
} | |
function isWithin6(value) { | |
return value.length <= 6 | |
} | |
function MyInput({ value, onChange: onChangeProp }) { | |
function onChange(e) { | |
if (isDigits(e.target.value) && isWithin6(e.target.value)) { | |
onChangeProp(e) | |
} | |
} | |
return ( | |
<div> | |
<input type='text' value={value} onChange={onChange} /> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment