Created
October 28, 2014 14:28
-
-
Save nadeem-khan/894c1929049545f7a489 to your computer and use it in GitHub Desktop.
Allow only alphanumeric characters in text input field with Jquery
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() { | |
$('#sidebar-filters-submit').click(function(e) { | |
$(".navigation").find(".error").remove(); | |
allOk = true; | |
if ($("#search_page_keywords").val()) { | |
var input = $("#search_page_keywords").val(); | |
if (/^[a-zA-Z0-9 ]*$/.test(input) === false) { | |
$("<label for=\"search_keyword_input\" class=\"search_keyword_input error\"> Your search string contains illegal characters.</label>").insertAfter("#search_page_keywords"); | |
allOk = false; | |
} | |
if (!allOk) { | |
e.preventDefault(); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment