1

I am use angular js 1.4 version. I am checked this link and checked with regular expression too, but not help me. When I try '2013-11-33' (in above link), its validate true, which is wrong.

enter image description here

This is my html

.. <div class="form-item">
    <!--<input required ng-model="dob" placeholder="Date of Birth* dd/mm/yyyy" class="textbox-n dob" type="text" onfocus="(this.type='date')" id="dobTxt" name="dobTxt" min="1910-01-01" max="2013-12-31">-->
    <input required ng-model="user.dob" placeholder="Date of Birth* dd/mm/yyyy" class="dob" type="text" id="dobTxt" name="dobTxt">    
</div> 
.....
<!--Validation Summary-->
                <div class="alert alert-danger validationSum" role="alert" style="margin-bottom: -20px;"
                     ng-show="submitted &&
                     (registerForm.genderSelect.$error.required
                     || registerForm.firstNameTxt.$error.required || registerForm.lastNameTxt.$error.required
                     || registerForm.dobTxt.$error.required || registerForm.dobTxt.$error.date
                     || registerForm.mobileTxt.$error.required
                     || registerForm.emailTxt.$error.required || registerForm.emailTxt.$error.email || (user.email != confirmEmail) || emailExist
                     || registerForm.pharmacySelect.$error.required)">
                    <ul>
                        <li ng-show="registerForm.genderSelect.$error.required">
                            Gender is required.
                        </li>
                        <li ng-show="registerForm.firstNameTxt.$error.required">
                            First name is required.
                        </li>
                        <li ng-show="registerForm.lastNameTxt.$error.required">
                            Last name is required.
                        </li>
                        <li ng-show="registerForm.dobTxt.$error.required">
                            Date of birth is required.
                        </li>
                        <li ng-show="registerForm.dobTxt.$error.date">
                            Not a valid date!
                        </li>
                        <li ng-show="registerForm.mobileTxt.$error.required">
                            Contact number is required.
                        </li>
                        <li ng-show="registerForm.emailTxt.$error.required">
                            Email is required.
                        </li>
                        <li ng-show="registerForm.emailTxt.$error.email">
                            Invalid email.
                        </li>
                        <li ng-show="isEmailMatched = (user.email != confirmEmail)">
                            Emails have to match!
                        </li>
                        <li ng-show="registerForm.pharmacySelect.$error.required">
                            Preferred pharmacy is required.
                        </li>
                        <li ng-show="emailExist">
                            This email has already been used to complete a questionnaire. Please contact your practitioner for your assessment.
                        </li>
                    </ul>
                </div>

Issue is when I entered wrong date , it is not fired. I tried some other links and plunker changes, but not resolve the issue.

Community
  • 1
  • 1
Ajay2707
  • 5,690
  • 6
  • 40
  • 58

1 Answers1

0

The issue is that you aren't validating user.dob anywhere. You only check to see if dobTxt has input in the form of a date, but not whether or not that is a valid date. Here and here are some examples of how to validate a date.

Community
  • 1
  • 1
senschen
  • 794
  • 10
  • 27
  • That is done in ' || registerForm.dobTxt.$error.required || registerForm.dobTxt.$error.date' here, and your link is for javascript, I want through angular.js – Ajay2707 Mar 28 '16 at 14:50
  • Angular.js is a javascript framework. Your angular controller is written in javascript, so the links I provided are valid and useful here. `registerForm.dobTxt.$error.required` checks to see that there is something in `dobTxt`, and `registerForm.dobTxt.$error.date` checks to see that it is in a valid *date format*, but does not check to see that that date is *valid*. You have to validate the date yourself. – senschen Mar 28 '16 at 14:58
  • I understand, but what I will do next, how to check format via function. If you have toughs with above link, please suggest i.e. with sample code. – Ajay2707 Mar 29 '16 at 11:50
  • There's sample code in the links. That's why I provided them. – senschen Mar 29 '16 at 11:55