You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.7 KiB
50 lines
1.7 KiB
import { Component, OnInit, Input } from '@angular/core'; |
|
import { NzModalRef } from 'ng-zorro-antd/modal'; |
|
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
import { HttpClient } from '@angular/common/http'; |
|
import { NzSafeAny } from 'ng-zorro-antd/core/types'; |
|
@Component({ |
|
selector: 'app-addcamera', |
|
templateUrl: './addcamera.component.html', |
|
styleUrls: ['./addcamera.component.scss'] |
|
}) |
|
export class AddcameraComponent implements OnInit { |
|
|
|
validateForm!: FormGroup; |
|
constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient) { } |
|
|
|
ngOnInit(): void { |
|
const { namevalidate } = MyValidators; |
|
this.validateForm = this.fb.group({ |
|
name: [null, [Validators.required, namevalidate]], |
|
user: [null, [Validators.required]], |
|
password: [null, [Validators.required]], |
|
uri: [null, [Validators.required]], |
|
type: [null, [Validators.required]], |
|
// order: [null, [Validators.required]], |
|
}); |
|
} |
|
|
|
|
|
} |
|
export type MyErrorsOptions = { 'zh-cn': string; en: string } & Record<string, NzSafeAny>; |
|
export type MyValidationErrors = Record<string, MyErrorsOptions>; |
|
export class MyValidators extends Validators { |
|
static namevalidate(control: AbstractControl): MyValidationErrors | null { |
|
const value = control.value; |
|
|
|
if (isEmptyInputValue(value)) { |
|
return null; |
|
} |
|
|
|
return isPassword(value) ? null : { mobile: { 'zh-cn': `名称只能是汉字、大小写英文、数字,不能使用特殊字符`, en: `not valid` } }; |
|
} |
|
|
|
} |
|
|
|
function isEmptyInputValue(value: NzSafeAny): boolean { |
|
return value == null || value.length === 0; |
|
} |
|
function isPassword(value: string): boolean { |
|
return typeof value === 'string' && /^[\u4E00-\u9FA5A-Za-z0-9]+$/.test(value); |
|
}
|
|
|