Angular 角度验证器生产

Angular 角度验证器生产,angular,validation,Angular,Validation,我在我的网站上有一个用户注册表单,在那里我使用自定义验证程序来检查注册密码。它在开发(ng serve)中按预期工作,但当我生成生产版本时(ng build--prod)特殊字符部分停止正常工作。控制台是干净的 你知道为什么会这样吗 密码验证程序: password: new FormControl('', [ Validators.required, Validators.minLength(8), this.CustomValidator.re

我在我的网站上有一个用户注册表单,在那里我使用自定义验证程序来检查注册密码。它在开发(ng serve)中按预期工作,但当我生成生产版本时(ng build--prod)特殊字符部分停止正常工作。控制台是干净的

你知道为什么会这样吗

密码验证程序:

password: new FormControl('', [
        Validators.required,
        Validators.minLength(8),
        this.CustomValidator.regTest(/[A-Z]/, true, 'upperCase'),
        this.CustomValidator.regTest(/[a-z]/, true, 'lowerCase'),
        this.CustomValidator.regTest(/[0-9]/, true, 'number'),
        this.CustomValidator.regTest(/[\!\"\#\¤\%\&\/\(\)\=\?\¨\^\'\*\<\>\,\;\.\:\-\_\§\½\@\£\$\€\{\}\[\]]/, true, 'special'),
        this.CustomValidator.regTest(/\s/g, false, 'blank')
      ])
显示验证状态的组件的一部分:

<div class="error-container" fxFlex="100%" *ngIf="regForm.get('password').value">
      <mat-error *ngIf="regForm.get('password').getError('special')">
        Password must contain at least 1 special character
      </mat-error>
    </div>

密码必须至少包含1个特殊字符

不确定为什么它作为开发构建工作,而不是在生产过程中工作,但将特殊字符的验证更改为下面的版本修复了该问题。对于特殊字符验证要求,它也是一种更干净、更广泛的方法

this.CustomValidator.regTest(/\W|_/, true, 'special')
this.CustomValidator.regTest(/\W|_/, true, 'special')