Skip to content

Instantly share code, notes, and snippets.

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 Soft-Designs/f114c90795eddee826d0343d562dc8f6 to your computer and use it in GitHub Desktop.
Save Soft-Designs/f114c90795eddee826d0343d562dc8f6 to your computer and use it in GitHub Desktop.
WPMU-Forminator-Custom-Validation
<?php
add_action(
'wp_footer',
function() {
?>
<script>
( function ( $ ) {
$( document ).ready( function() {
var cvalinput = $( '.custom-validate input' ),
regx = /^[A-Za-z0-9]+$/;
$( cvalinput ).focusout( function() {
if ( regx.test( $( this ).val() ) || $( this ).val() === '' ) {
$( this ).parent().parent().find( 'label.forminator-label--validation' ).remove();
} else {
if ( ! $( this ).parent().parent().find( 'label.forminator-label--validation' ).length ) {
$( this ).parent().parent().append( '<label class="forminator-label--validation">Only alphanumeric characters are allowed.</label>' );
}
}
} );
} );
} ( jQuery ) )
</script>
<?php
},
999
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment