Reputation: 6959
How to validate special characters (like @ # $ %), but allow international (European) language characters?
I'm using jQuery validation.
My current code is:
$('#my_form').validate({
rules: {
'model[field]': {
required: true,
noSpecialCaracters: true
}
}
});
This show errors message on typing special characters like: ö ä å ø æ
Upvotes: 3
Views: 1033
Reputation: 117
$('#my_form').validate({
rules: {
'model[field]': {
required: true,
noSpecialCaracters:function() { return /^[0-9a-zñáéíóúü]+$/i.test(string); }
}
});
Upvotes: 0
Reputation: 1556
You can add a custom validation method which uses Regex to validate the input allowing alphabetical letters and the special characters you defined.
$.validator.addMethod('customValidation',
function(value, element) {
return this.optional(element) ||
/^[A-Za-z\u00C0-\u017F]+$/.test(value); },
'Bad validation message here.');
Upvotes: 3