Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* onKeyUp(e)
* when a key is pressed up, grab the contents in that
* input field, format them in line with XXX-XXX-XXXX
* format and validate if the text is infact a complete
* phone number. Adjust the border color based on the
* result of that validation
function onKeyUp(e){
var input =;
var formatted = formatPhoneText(input.value);
var isError = (validatePhone(formatted) || formatted.length == 0);
var color = (isError) ? "gray" : "red";
var borderWidth = (isError)? "1px" : "3px"; = color; = borderWidth;
input.value = formatted;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment