Angular8:新用户注册时的电子邮件验证

时间:2019-07-11 09:22:22

标签: angular email laravel-5.8 angular8

我想在新用户注册/注册时实施电子邮件验证。我从前端使用Angular,从后端使用Laravel。什么是实现这一目标的最佳方法?希望您会有所帮助,并先谢谢您。

2 个答案:

答案 0 :(得分:0)

假设我们有 component.html [使用angular material2 UI框架]。在这里,您可以自由选择任何框架来实现此目的。

<mat-form-field color="accent">
                    <input matInput placeholder="Email" [formControl]="email" required>
                    <mat-error *ngIf="email.invalid">[[getErrorMessage()]]</mat-error>
                </mat-form-field>

component.ts

import { FormGroup, FormControl, Validators} from '@angular/forms';


 @Component({
     selector: 'form-create',
     templateUrl: './component.html',
     styleUrls: ['./component.scss'], 
 })
 export class FormComponent implements OnInit {

   email   = new FormControl('', [Validators.required, Validators.email]);

   sampleForm = new FormGroup({
                      email  : this.email,
                         ..........
   });

   getErrorMessage() {
        return this.email.hasError('required') ? 'You must enter a value' :
            this.email.hasError('email') ? 'Not a valid email' : '';
    }


 }

上面提供了关于FE本身的各种验证。我们可以修改 getErrorMessage()以显示来自服务器端的自定义错误消息。

从未使用过 Laravel ,因此请使用此示例进行指导。

答案 1 :(得分:0)

您应该同时在正面和背面进行验证。

您可以在前面使用此https://angular.io/api/forms/EmailValidator

后面……我不是PHP专家,但是您可以使用此https://medium.com/@pran.81/how-to-implement-laravels-must-verify-email-feature-in-the-api-registration-b531608ecb99

相关问题