I'm working in php with codeigniter and i need to so some form validation. Specifically, using Codeigniter's validation form library i coded this for name field:
$this->form_validation->set_rules('name', 'Nombre', 'required|min_length[2]|max_length[50]|regex_match[/^([a-z,A-Z,á,é,í,ó,ú,â,ê,ô,ã,õ,ç,Á,É,Í,Ó,Ú,Â,Ê,Ô,Ã,Õ,Ç,ü,ñ,Ü,Ñ," "]+)$/]');
As you can see it accepts international characters for different kinds of names.
Now i want to do the same but on the front, making the same regular expression in jQuery.
I am using pattern method form additional-methods.js so this is the snippet from it to "build" the regular expression:
jQuery.validator.addMethod("pattern", function(value, element, param) {
if (this.optional(element)) {
return true;
}
if (typeof param === 'string') {
param = new RegExp('^(?:' + param + ')$');
}
return param.test(value);
}, "Formato Inválido.");
Then on my js file what i have is this (snippet):
form2.validate({
errorElement: 'span', //default input error message container
errorClass: 'help-inline', // default input error message class
focusInvalid: false, // do not focus the last invalid input
ignore: "",
rules: {
name: {
minlength: 2,
maxlength: 50,
pattern: "[\s,.'-]*[a-zA-Z\pL][\s,.'-]*", //not working
required: true
},
I've tried with many regular expressions, but it's not working. It also has to accept accents like: mathías, damián, and so on.
Can anyone give me a hand? thanks