Add minLength and maxLength to Validator
This commit is contained in:
parent
de777bc844
commit
b401c9732c
@ -86,6 +86,30 @@ export default class Validator<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param minLength included
|
||||||
|
*/
|
||||||
|
public minLength(minLength: number): Validator<T> {
|
||||||
|
this.addStep({
|
||||||
|
verifyStep: val => (<any>val).length >= minLength,
|
||||||
|
throw: () => new BadLengthValidationError(minLength, 1000000),
|
||||||
|
isFormat: true,
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param maxLength included
|
||||||
|
*/
|
||||||
|
public maxLength(maxLength: number): Validator<T> {
|
||||||
|
this.addStep({
|
||||||
|
verifyStep: val => (<any>val).length <= maxLength,
|
||||||
|
throw: () => new BadLengthValidationError(0, maxLength),
|
||||||
|
isFormat: true,
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param minLength included
|
* @param minLength included
|
||||||
* @param maxLength included
|
* @param maxLength included
|
||||||
|
Loading…
Reference in New Issue
Block a user