0

<form name="LPform">
    <div class="form-row clearfix">
         <label class="lbl-fld" style="margin-left: 12%;">Email ID</label>
         <input class="mob-adj-inpbx" type="email" name="uemail" ng-model="useremail" placeholder=" [email protected]" ng-required="true"/>
         <div ng-show="LPform.uemail.$valid">Enter a valid email.</div>
    </div>
</form>

Here, I'm adding validations to 'email' and trying to display error message only when the user enters invalid email. However this is not working.

3
  • Can you please fiddle the proper angular code Commented Jan 21, 2016 at 6:21
  • sorry... didn't get u. I have added the controller and everything else on the page is working fine. "LPform.uemail.$valid" is not working. I'm not sure if I have to add any method or variable in js file Commented Jan 21, 2016 at 6:29
  • i mean to say tha please share the whole html and javascript code. So that others can help it out. Also make a fiddle on jsfiddle.net Commented Jan 21, 2016 at 6:31

1 Answer 1

1
  1. I suppose you want to show the error message if the input is invalid so

    ng-show="!LPform.uemail.$valid"

  2. Maybe you forgot to bind it to a scope variable? cause it seems to work fine.

function Ctrl($scope) {
  $scope.useremail = '';
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<div ng-app>
  <div ng-controller="Ctrl">
    <form name="LPform">
      <div class="form-row clearfix">
        <label class="lbl-fld">Email ID</label>
        <input class="mob-adj-inpbx" type="email" name="uemail" ng-model="useremail" placeholder=" [email protected]" ng-required="true" />
        <div style="font-size: 11px; color: red; margin: 5px 65px;" 
             ng-show="!LPform.uemail.$valid">Please enter a valid email.</div>
      </div>
    </form>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. It worked fine with ng-show="LPform.uemail.$error.email"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.