Skip to content

Instantly share code, notes, and snippets.

@hopeseekr
Created October 3, 2019 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hopeseekr/ef8407b238a3163a01f68e24f7b706ca to your computer and use it in GitHub Desktop.
Save hopeseekr/ef8407b238a3163a01f68e24f7b706ca to your computer and use it in GitHub Desktop.
Formatting phones
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