Created
May 11, 2017 12:49
-
-
Save fjcunha/bebdd970fd753c9781767b260bc46de8 to your computer and use it in GitHub Desktop.
Input mask when not work in sony, samsung devices.
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
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