Last active
November 3, 2015 03:19
-
-
Save craigbutcher/59752be0460c7776569f to your computer and use it in GitHub Desktop.
jQuery Validation - No Special Characters allowed (not allowing < > # )
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
// 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