|
|
|
@ -1,7 +1,8 @@
|
|
|
|
|
import { Component, OnInit, Input } from '@angular/core'; |
|
|
|
|
import { NzModalRef } from 'ng-zorro-antd/modal'; |
|
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
|
|
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', |
|
|
|
@ -13,8 +14,9 @@ export class AddcameraComponent implements OnInit {
|
|
|
|
|
constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient) { } |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
const { namevalidate } = MyValidators; |
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
name: [null, [Validators.required]], |
|
|
|
|
name: [null, [Validators.required, namevalidate]], |
|
|
|
|
user: [null, [Validators.required]], |
|
|
|
|
password: [null, [Validators.required]], |
|
|
|
|
uri: [null, [Validators.required]], |
|
|
|
@ -25,3 +27,24 @@ export class AddcameraComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
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: `Password phone number is 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); |
|
|
|
|
} |
|
|
|
|