中英文混合时,校验字节长度,充分利用数据库定义的长度。先上图为敬:
资源地址:https://www.npmjs.com/package/great-ngform
示例代码:
ngOnInit() {
this.form = this.fb.group({
byteLength: new FormControl(null, [
this.formValidatorService.byteLength({
maxLength:10,
})
]),
byteLength1: new FormControl(null, [
this.formValidatorService.byteLength({
length:10
})
]),
byteLength2: new FormControl(null, [
this.formValidatorService.byteLength({
minLength:10
})
]),
byteLength3: new FormControl(null, [
this.formValidatorService.byteLength({
minLength:5,
maxLength:10
})
]),
byteLength4: new FormControl(null, [
this.formValidatorService.byteLength({
minLength:5,
errorMsg: '最少输入5个字节!',
}),
this.formValidatorService.byteLength({
maxLength:10,
errorMsg: '最多输入10个字节!'
}),
this.formValidatorService.required({
errorMsg: '必填项不能为空!'
})
]),
});
}