2

I need to get an error when the user selects the year 2016 in my calendar UI date-picker. I'm using jQuery plugins for error messages. This is my script:

$(document).ready(function(){
    $("#datepicker").click(function(){

        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange: "1930:2016",
            dateFormat : 'dd-mm-yy'
        });

        $( "#datepicker" ).datepicker("show");
    });
});

This is my HTML:

<div class="row">
    <div class="col-sm-4">
        <div class="form-group field-user-user_dob has-success">
            <label class="control" for="user-user_dob">Date of Birth</label>
            <input type="text" id="datepicker" class="form-control" name="datepicker" readonly size="12">
            <div class="help-block"></div>
        </div>
    </div>
</div>

1 Answer 1

5

You can find the selected year on the datepicker using the solution written here. After finding the date you can check that and throw an error message as well.

In another sense, you can get the total value and extract the year from the value (as you are defining the deatFormat). And you can through error depending on that.

Hope it helps..:)

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

Comments

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.