EduardET

prevent special characters to be entered in search input

Jan 12th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. ( function( $ ) {
  3.     $( document ).ready( function() {
  4.         var searchInput = $( '.et_pb_s' );
  5.         if ( searchInput.length ) {
  6.             $( '.et_pb_s' ).keypress( function( event ) {
  7.                 var character = String.fromCharCode( event.keyCode );
  8.                 return isValid( character );
  9.             } );
  10.  
  11.             function isValid( str ) {
  12.                 return !/[~`!@#$%\^&*()+=\-\[\]\\';,/{}|\\":<>\?]/g.test( str );
  13.            }
  14.        }
  15.    } );
  16. } )( jQuery );
  17. </script>
Advertisement
Add Comment
Please, Sign In to add comment