nghuuphuoc/bootstrapvalidator — pull request #479 by mbezhanov (2014-07-09 07:49:46+00:00)
Title: allow validation of a value from a list of options

Hello Nguyen,

I wrote this for a project I worked on and decided to share. It probably needs additional coding, so let me know if I have to apply any changes to it or if it's not a suitable contribution for some reason.

My idea here is the following: there are times, when you have SELECT fields that present a very specific list of options. Sometimes, there are users maliciously probing your back end, by altering the OPTIONs of your SELECTs (with tools like Firebug etc.) and submitting your forms to see what's going to happen. Of course, you can't rely on JavaScript validation to prevent injections to your backend, however with this additional "allowed value" validation, I'm successfully stopping less knowledgeable users from submitting their forms after altering the contents of the featured SELECTs.

You can really use it for comparing a value, against any pre-defined array of values, and not necessarily with SELECTs only (can be easily used for INPUT fields too)

Here is a practical example - a store owner selling items strictly in batches of 50, 100, 150 or 200:

```javascript
amount: {
validators: {
notEmpty: {
message: 'The amount is required and cannot be empty.'
},
allowedValue: {
allowedValues: ['50','100','150','200'],
message: 'The specified amount is invalid.'
}
}
}
```