Created
October 3, 2019 00:48
-
-
Save hopeseekr/ef8407b238a3163a01f68e24f7b706ca to your computer and use it in GitHub Desktop.
Formatting phones
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
phone: { | |
get: function() { | |
return this.value; | |
}, | |
// setter | |
set: function(newValue) { | |
if (newValue.length === 1) { | |
this.value = "(" + newValue; | |
} else if (newValue.length === 4) { | |
this.value = newValue + ") "; | |
} else if (newValue.length === 9) { | |
// (282) 922-5555 | |
// 1234567890 | |
this.value = newValue + "-"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment