<label>Year</label>
<asp:Textbox id="year" runat="server" placeholder="year">
To try enter this textbox to allow this text box only allow till 2018.thanks in advance.
If you want to have it in simple html we have attribute max
<input type="number" id="year" max="2018" message="Year should be less that 2019"/>
Or in jQuery
$(document).ready(function(){
$("#year").on('input',function(){
if(parseInt($(this).val()) > 2018){
alert('Year must be less than 2019');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>Year</label>
<input type="number" id="year" placeholder="year">
2019 and then right click the field and choose 'paste' the value will be entered without validation. In other words, always use the input event, not keyup.Please try below code and don't forget to check the datatype too:-
<script>
/* code for jQuery */
$('#id').click(function(){\
if($('#year').val() > 2018){
//html message or alert box whatever you want.
}
});
/*code for core javascript */
function checkYear(){
var year = document.getElementById('year').value;
if(year > 2018){
//html message or alert box whatever you want.
}
}
</script>
selectwith year options descending from the current? Much simpler to implement and zero input validation required