Skip to content

Instantly share code, notes, and snippets.

@asimmittal
Created February 12, 2017 01:44
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 asimmittal/c0c3e1059d87b991f4a27b428ba8589a to your computer and use it in GitHub Desktop.
Save asimmittal/c0c3e1059d87b991f4a27b428ba8589a to your computer and use it in GitHub Desktop.
/*******************************************************
* 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 = e.target;
var formatted = formatPhoneText(input.value);
var isError = (validatePhone(formatted) || formatted.length == 0);
var color = (isError) ? "gray" : "red";
var borderWidth = (isError)? "1px" : "3px";
input.style.borderColor = color;
input.style.borderWidth = borderWidth;
input.value = formatted;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment