-1
How to do date validation from Editorfor using jquery? wanted to check if the date typed by the user, and if the date he typed is greater than the current date, display a message to him stating the error
<div class="form-group">
@Html.LabelFor(model => model.DataNascimento, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataNascimento, new { htmlAttributes = new { @class = "form-control data" } })
@Html.ValidationMessageFor(model => model.DataNascimento, "", new { @class = "text-danger" })
</div>
</div>
thought to do a jquery that picks up the typed content and checks the date. Someone can help me?
with the help of @Lucasdefreitaskauer this script has been made:
$("#DataDeNascimento").on("blur", validarDataDeNascimento);
var validarDataDeNascimento = function () {
var dataDeNascimentoStr = $("#DataDeNascimento").val();
var dataDeNascimento = new Date(dataDeNascimentoStr);
var agora = new Date();
if (dataDeNascimento > agora) {
alert("A data de nascimento não pode ser uma data futura.");
}
};
and was added to Editorfor the ID id = "Dated" but when you lose Focus(Blur) it shows no warning.
What exactly do you want to validate? Could explain your problem better?
– Lucas Kauer
I edited the question
– Fabio Souza
Why did you put "- Pending" in the title of the question?
– Jéf Bueno