0

I'm trying to validate user's input onto the email address field inside a form, and I used to create a span in which the error message gets generated in the case of typing an invalid value. This is the span HTML code:

<div ng-app="app" ng-controller='signupCtrl'>
          <span style="padding: 2px 0 2px 16px; color: red;" ng-if="check_mail()">Please type a valid email address</span>
          </div>

I used the ng-if tag for conditionally binding the error message

Please type a valid email address

, and check_mail() function for checking the value from a signupCtrl controller.

The check_mail function works fine as expected. However the error message was never displayed though. So is there anything wrong on my HTML code? How is it possible to solve this problem?

Thanks.

10
  • 1
    Sorry if it's a basic question but does check_mail() function return boolean? Commented May 23, 2016 at 15:01
  • 1
    @user6039980 can we see your check_mail function? Commented May 23, 2016 at 15:06
  • 1
    could you provide a plunkr of your code? Commented May 23, 2016 at 15:06
  • 1
    @user6039980 There is nothing wrong with your set up but if the function is returning false then it wouldn't show up all. try changing it to return true or !check_mail() Commented May 23, 2016 at 15:13
  • 1
    can you provide your check_mail function? Commented May 23, 2016 at 15:14

1 Answer 1

1

does the function check_mail() returns true if the mail is invalid? if it doesnt then you may want to try

<div ng-app="app" ng-controller='signupCtrl'>
      <span style="padding: 2px 0 2px 16px; color: red;" ng-if="!check_mail()">Please type a valid email address</span>
      </div>
Sign up to request clarification or add additional context in comments.

4 Comments

That's what I had exactly to do. Thanks for this perfect answer!
Did you just steal my answer? =(
@kugyousha I didn't, and I cant see the exact time when you posted it, it says 3 hours on both your comment and my answer, it wasn't exactly a very complex answer, so can see how we both got to the same conclusion, however, if your's was first (again, I can't see the exact time) I have no problem with you posting an answer and the OP accepting it as the best answer.
@ArturoMontaño I'm just teasing, I don't care about the points ;) I appreciate your civility. You're right it was a really simple answer and we did come up with it at almost the same time either way.

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.