Created
May 1, 2018 04:06
-
-
Save msankhala/6683d283a63c5abbacf104213b8177c0 to your computer and use it in GitHub Desktop.
html5-custom-validation-pattern.js
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
jQuery(document).ready(function(){ | |
jQuery('#edit-default-value-input-field-email-0-value').on('input', function(event){ | |
var constraint = new RegExp(/^\[[\w\d][\w\d_\-]*:[\w\d_\-]*\]$/); | |
if (constraint.test(event.target.value)) { | |
console.log(event.target); | |
this.setCustomValidity(''); | |
} | |
else { | |
console.log(event.target); | |
this.setCustomValidity('This is not a valid token'); | |
} | |
}); | |
}); | |
function validateToken() { | |
constraint = new RegExp(/^\[[\w\d][\w\d_\-]*:[\w\d_\-]*\]$/); | |
var elem = document.getElementById('edit-default-value-input-field-email-0-value'); | |
if (constraint.test(elem.value)) { | |
console.log(elem.checkValidity()); | |
elem.setCustomValidity(''); | |
return; | |
} | |
console.log(elem.checkValidity()); | |
this.setCustomValidity('This is not a valid token'); | |
} | |
document.getElementById('edit-default-value-input-field-email-0-value').oninput = validateToken; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment