gpt4 book ai didi

javascript - Angular js 电子邮件验证不适用于域名

转载 作者:行者123 更新时间:2023-11-28 04:10:12 24 4
gpt4 key购买 nike

您好,我正在开发 AngularJS 应用程序,其中我正在对电子邮件 ID 进行验证。每当我输入 test@test 时,都会出现错误消息。但它不起作用。

下面是我的代码。

       <div class="inputblock with-icon mail" ng-class="{ 'has-error' : ((form.$submitted && form.email.$invalid)|| (form.email.$invalid && form.email.$dirty))}">
<label class="inputblock-label" ng-show="user.email">{{ 'Email' | translate }}</label>
<span class="input-icon"><img src="images/mail-icon.png"></span>
<div>
<span class="ang-error" style="color:#fff" ng-show="form.email.$dirty && form.email.$invalid">
<span ng-show="form.email.$error.required && form.email.$dirty">* {{'Required' | translate}}</span>
<span style="color:#fff" ng-show="form.email.$error.email">{{'Invalid EmailId' | translate}}</span>
</span>
</div>
<input type="email"
class="with-icon"
ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/"
placeholder="{{ 'Email' | translate }}"
ng-model="user.email"
required=""
name="email"
my-maxlength="50">
</div>

每当我输入 test@test 时,我都可以在浏览器中看到以下代码

<input type="email" class="with-icon ng-dirty ng-valid-required ng-invalid ng-invalid-pattern ng-valid-email ng-touched" ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/" placeholder="Email" ng-model="user.email" required="" name="email" my-maxlength="50" ng-trim="True">

下面是我输入test@test时的字段屏幕截图 enter image description here

下面是我输入test@时的屏幕截图 enter image description here

我可以知道如何修复上述错误吗?任何帮助,将不胜感激。谢谢

最佳答案

你可以试试这个:

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,3}$/;
$scope.model = "test@test";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">
<form name="form">
<input type="text" ng-model="model" id="input" name="input" ng-pattern="emailPattern" /><br>
<p>input valid? = {{form.input.$valid}}</p>
</form>
</div>

关于javascript - Angular js 电子邮件验证不适用于域名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46363984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com