Javascript 角度形式的Toastr消息
我有一个棱角形。因此,在字段中,我已设置为要验证的STR消息,以便不会提交空字段。它工作正常,并显示toastr消息,但当我输入两个空格并提交表单时,它仍然接受并提交表单。我想要一条toastr消息,当我们输入两个空格或空空格并提交时,显示表单字段为空。有什么方法可以对其进行排序吗Javascript 角度形式的Toastr消息,javascript,angular,angular-material,Javascript,Angular,Angular Material,我有一个棱角形。因此,在字段中,我已设置为要验证的STR消息,以便不会提交空字段。它工作正常,并显示toastr消息,但当我输入两个空格并提交表单时,它仍然接受并提交表单。我想要一条toastr消息,当我们输入两个空格或空空格并提交时,显示表单字段为空。有什么方法可以对其进行排序吗 ngOnInit(): void { this.customerForm = this.fb.group({ name: ['', Validators.required], custom
ngOnInit(): void {
this.customerForm = this.fb.group({
name: ['', Validators.required],
customer_id: ['', Validators.required],
})
}
if (this.customerForm.value.customer===""){
this.toastr.error('Add customer field' ,{timeOut: 1500});
return false;
}
<td>
<mat-form-field>
<mat-label>Name</mat-label>
<input matInput placeholder="Name" formControlName="name" autocomplete="off" required>
</mat-form-field></td>
ngOnInit():void{
this.customerForm=this.fb.group({
名称:['',验证器。必需],
客户id:['',验证器。必需],
})
}
if(this.customerForm.value.customer==“”){
this.toastr.error('addcustomer字段',{timeOut:1500});
返回false;
}
名称
< /代码> 您可以在将字符串与空白字符串进行比较之前,从字符串的开始和结束移除空白。
if (this.customerForm.value.customer.trim() === ""){
this.toastr.error('Add customer field', {timeOut: 1500});
return false;
}
嘿,谢谢,这很有效。如果用户在toastr的表单字段中最多只能输入20个字符,您能提供帮助吗?任何超过20个字符的内容都应该显示toastr消息this.customerForm.value.customer.trim().length>20