angularJs电子邮件验证失败

时间:2015-02-27 06:37:18

标签: angularjs validation

有角度的电子邮件验证对我不起作用,我不允许在电子邮件文本框中输入任何文字。

以下是我的HTML:



<form name="locationSettingsForm" ng-submit="vm.saveLocationSettings()" class="form">
  <input class="userInput" style="width:40%" type="email" name="email"
   maxlength="50" data-ng-model="vm.location.email" required
   ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/" />
   <label class="validationErrorText" data-ng-show="locationSettingsForm.email.$dirty && locationSettingsForm.email.$error.email">Email is invalid</label>
   <label class="validationErrorText" data-ng-show="locationSettingsForm.email.$dirty && locationSettingsForm.email.$error.required">Email is required</label>
</form>
&#13;
&#13;
&#13;

最初我试过没有ng-patter。我只使用了type =&#39; email&#39;,但在这两种情况下它都没有用。我无法输入任何文字。

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试这种模式

ng-pattern="/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,15})$/"

它应该有用

答案 1 :(得分:0)

您可以尝试以下代码....

<input type="email" id="inputEmail" ng-model="email" name="uEmail" placeholder="Email Id" required>
        <div ng-show="form.uEmail.$dirty && form.uEmail.$invalid">Invalid:
  <span ng-show="form.uEmail.$error.required">Tell us your email.</span>
  <span ng-show="form.uEmail.$error.email">This is not a valid email.</span>