Created
August 10, 2018 21:50
-
-
Save AndersonFirmino/1d477dfb43968d91ddc3b6f18a4bf3a1 to your computer and use it in GitHub Desktop.
maskDate JavaScript
This file contains 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
const maskDate = value => { | |
let v = value.replace(/\D/g,'').slice(0, 10); | |
if (v.length >= 5) { | |
return `${v.slice(0,2)}/${v.slice(2,4)}/${v.slice(4)}`; | |
} | |
else if (v.length >= 3) { | |
return `${v.slice(0,2)}/${v.slice(2)}`; | |
} | |
return v | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment