posabsolute/jQuery-Validation-Engine — Issue #249: How to define a rule (regexp or anything) in multiple languages without duplicating the rule
Author: phtrivier
Created: 2012-01-19 18:53:32+00:00
State: open

I am trying to define a business-specific validation rule, so that I could write , for example :

where 'foobar' means something complicated that can only be computed by calling a function.

So far the only way I have found to do that is to reduce the check to one of the built-in validators (say, regexp), and add, in *all* the languge files, a block like :

"foobar" : {
"regex" : /^[0-9a-zA-Z]+$/,
"alertText" : "* Your error message"
},

The problem is that then, the definition of the text (here, the regexp), gets duplicated in all your language files. This makes sense for some case (where the rule of validation really depends on the locale), but in the general case this looks really dangerous to me.

So what am I missing ? I've seen the 'funcCall' rule, how would you use it ? Is there a way to customize the validation rules without patching the library file, or mixing up code and error messages in the language-specific files ?

Thanks