Skip to content

Instantly share code, notes, and snippets.

@Teino1978-Corp
Created November 3, 2015 03:19
Show Gist options
  • Select an option

  • Save Teino1978-Corp/19fdd9f0259a836f51db to your computer and use it in GitHub Desktop.

Select an option

Save Teino1978-Corp/19fdd9f0259a836f51db to your computer and use it in GitHub Desktop.
jQuery Validation - No Special Characters allowed (not allowing < > # )
// Thanks to this site to help out on RegEx - http://www.regexr.com/
require(["jQueryValidate"], function(){
// dont allow < > # \ /
// add alphanumeric validator
jQuery.validator.addMethod("noSpecialCharacter", function(value, element) {
var regex = new RegExp("[<>#]+");
var key = value;
if (regex.test(key)) {
return false;
}
return true;
}, "please do not use the characters: < > #");
//login box
$('.loginBox form').validate({});
//advanced search
if (has('.advanced-search')) {
$('.advanced-search').validate({
rules: {
text: {
noSpecialCharacter: true
}
}
});
}
// feedback
$('.standard-validation').validate({
});
//register
if (has('#registration-form')) {
$('#registration-form').validate({
});
}
// site search
$('.search-validation form').each(function(){
$(this).validate({
rules: {
text: {
noSpecialCharacter: true
}
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment