I am using validate to validate input, and I need to validate an input that has to be one of the numbers in my arr
.
JavaScript
x
10
10
1
const arr = [1, 2, 4, 5, 9, 14];
2
3
const p = {
4
System: {
5
type: Number,
6
enum: arr,
7
required: true
8
}
9
};
10
If I try enum: arr
, then it takes the entire array and not just one of the elements.
Question
Is it possible to get validate
to use one of the numbers from arr
?
Advertisement
Answer
JavaScript
1
16
16
1
import Schema from 'validate'
2
const arr = [1, 2, 4, 5, 9, 14];
3
4
const p_schema = new Schema({
5
System: {
6
type: Number,
7
enum: [arr],
8
required: true
9
}
10
});
11
let p = {
12
System: 9
13
}
14
15
const errors = p_schema.validate(p)
16