Created
February 12, 2017 01:44
-
-
Save asimmittal/c0c3e1059d87b991f4a27b428ba8589a to your computer and use it in GitHub Desktop.
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
/******************************************************* | |
* 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