Created
September 29, 2014 10:34
-
-
Save Apina/bc1b19ff2f3c3b73b369 to your computer and use it in GitHub Desktop.
EE4 US Phone and Zip validation: This needs to be added to a custom functions plugin or similar. It is very basic, for instance it loads on every page rather than just EE related pages, but should provide a basis for allowing validation. Also note that the addClass required isn't strictly necessary but may be useful.
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
function dr_validate() { | |
wp_register_script( 'drvalid', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js', array('jquery'), '1.13.0', true ); | |
wp_register_script( 'drvalid2', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/additional-methods.min.js', array('jquery'), '1.13.0', true ); | |
wp_enqueue_script( 'jquery' ); | |
wp_enqueue_script( 'drvalid' ); | |
wp_enqueue_script( 'drvalid2' ); | |
} | |
add_action('wp_enqueue_scripts','dr_validate'); | |
function dr_validate_zip_phone() { | |
?> | |
<script type="text/javascript"> | |
jQuery( document ).ready(function() { | |
jQuery("#spco-registration-attendee_information-frm").validate(); | |
jQuery(".phone").rules("add", { | |
required: true, | |
phoneUS: true, | |
required: true | |
}).addClass('required'); | |
jQuery(".zip").rules("add", { | |
required: true, | |
digits: true, | |
minlength: 5, | |
maxlength: 5 | |
}); | |
}).addClass('required'); | |
</script> | |
<?php | |
} | |
add_action('wp_footer', 'dr_validate_zip_phone'); |
lorenzocaum
commented
Sep 29, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment