Skip to content

Instantly share code, notes, and snippets.

@fjcunha
Created May 11, 2017 12:49
Show Gist options
  • Save fjcunha/bebdd970fd753c9781767b260bc46de8 to your computer and use it in GitHub Desktop.
Save fjcunha/bebdd970fd753c9781767b260bc46de8 to your computer and use it in GitHub Desktop.
Input mask when not work in sony, samsung devices.
function unmask(val) {
return val.replace(/\D+/g, '');
}
function formatDate(ev) {
console.log(ev.value);
var cleanText = unmask(ev.value);
var result = cleanText;
if (cleanText.length > 2) {
result = cleanText.substr(0, 2) + "/" + cleanText.substr(2);
}
if (cleanText.length > 4) {
result = cleanText.substr(0, 2) + "/" + cleanText.substr(2, 2) + "/" + cleanText.substr(4);
}
ev.value = result;
setTimeout(function () {
ev.selectionStart = ev.value.length;
ev.selectionEnd = ev.value.length;
}, 30);
console.log(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment