Skip to content

Instantly share code, notes, and snippets.

@dave-martinez
Created April 5, 2018 04:28
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 dave-martinez/77f4517e535e27a8f0e416953bbcff90 to your computer and use it in GitHub Desktop.
Save dave-martinez/77f4517e535e27a8f0e416953bbcff90 to your computer and use it in GitHub Desktop.
// Kahit tanggalin mo na din yung pattern since nag JS validation na naman
<input type="text" name="contact" id="contact" maxlength=11 onchange="validateContact()">
function validateContact() {
// Palitan mo nalang yung id sa getElementById
var contactLength = document.getElementById('contact').value.length;
var submitButton = document.getElementById('theSubmit');
if(contactLength == 7 || contactLength == 11) {
submitButton.disabled = false;
} else {
alert('Invalid number length');
submitButton.disabled = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment