【问题标题】:Angular Email Control valid even if the email format is inorrect [duplicate]即使电子邮件格式不正确,Angular 电子邮件控制也有效 [重复]
【发布时间】:2020-03-27 16:01:14
【问题描述】:

请检查代码:https://stackblitz.com/edit/angular-form-dirty-and-form-valid-check

这是一个简单的代码:

HTML:

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular';

  registerForm: FormGroup = new FormGroup({
    email: new FormControl(null, [Validators.required, Validators.email])
  })
}

TS 文件:

<form [formGroup]="registerForm" (ngSubmit)="registerNew()" class="text-center">
    <label for="email">Email</label>
    <input
    [class.is-invalid]="registerForm.get('email').invalid && registerForm.get('email').touched"
    type="text" id="email" formControlName="email" class="form-control">
    <br>
  <small *ngIf="registerForm.get('email').valid &&
                registerForm.get('email').dirty">
    Valid Email ID
  </small>
</form>

这似乎有问题。

当我输入电子邮件:没有“.com”的“a@gmail”时,它还会显示表明电子邮件有效的标签。

是功能不正确还是我在这里遗漏了什么?

-阿什

【问题讨论】:

  • 明白,您的意思是说“.com”可能需要也可能不需要。

标签: angular angular-forms


【解决方案1】:

根据我评论中链接的问题,并非所有主机的名称中都有一个点。 gmail 仍然是有效的主机或“域”,与 localhost 的意义相同。如果您在 localhost 上运行的邮件服务器已正确配置所有内容,则可以发送电子邮件至user@localhost

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多