角垫表格输入不抛出错误

时间:2018-12-05 15:09:46

标签: javascript html angular typescript

我有一个简单的文本输入字段,我的 checkUrlFormat()函数在.ts文件上运行良好,但是在这里什么也没显示,就好像没有检查一样。

<mat-form-field>
    <mat-label>Enter link here</mat-label>
    <input matInput [(ngModel)]="inputText">
    <mat-error *ngIf="checkUrlFormat()">
        Please enter the link in correct format
    </mat-error>
</mat-form-field>

and checkUrlFormat()是:

checkUrlFormat() {
    const pattern = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/;
    if (pattern.test(this.inputText)) {
        return false;
    }
    return true;
}

0 个答案:

没有答案