Skip to content

Instantly share code, notes, and snippets.

@AndersonFirmino
Created August 10, 2018 21:50
Show Gist options
  • Save AndersonFirmino/1d477dfb43968d91ddc3b6f18a4bf3a1 to your computer and use it in GitHub Desktop.
Save AndersonFirmino/1d477dfb43968d91ddc3b6f18a4bf3a1 to your computer and use it in GitHub Desktop.
maskDate JavaScript
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