I need to do a validation on the start date and end date with javascript

Asked

Viewed 327 times

0

I need to do a validation on the start date and end date... So that the end date may not be less than the start date, but as I started messing with javascript less than two weeks ago I’m hitting myself a little. It would be this case below: So much for DataInicioCurso and DataFimCurso how much to DataInicioDisciplina and DataFimDisciplina.

Could I get a validation around here? Thanks in advance!

function PreencherDadosTurma(data) {

    var turma = data;

    turma.IdInstituicaoDeEnsino = jq.IdInstituicaoDeEnsino.val();
    turma.InstituicaoDeEnsino.IdRedeOfertante = jq.idRedeOfertante.val();
    turma.IdCurso = jq.IdCurso.val();
    turma.Descricao = jq.Descricao.val();
    turma.QtdEstudante = jq.QtdEstudante.val().ToInt32();
    turma.DataInicioCurso = jq.DataInicioCurso.val();
    turma.DataFimCurso = jq.DataFimCurso.val();
    turma.DataInicioDisciplina = jq.DataInicioDisciplina.val();
    turma.DataFimDisciplina = jq.DataFimDisciplina.val();
    turma.EmpreendedorismoAplicado = jq.EmpreendedorismoAplicadoSim.prop('checked') ? jq.EmpreendedorismoAplicadoSim.val() : jq.EmpreendedorismoAplicadoNao.val();
    turma.IdTurma = jq.IdTurma.val().ToInt32();

    return turma;
}
  • Friend, look for the momentJs library, it is magical!

  • Hello, you can use Jqueryvalidation. http://jqueryvalidation.org/. and an example of how it uses http://stackoverflow.com/questions/19773931/validation-date-input-min-and-max-value

  • You can use the validation of the . net itself, I think it is better if you want I can make an answer.

  • @Diegofilipepedrosantos I want yes, please :)

  • @Marianeribeiro came to look managed to do something?

  • @Diegofilipepedrosantos Hello Diego, yes I did and I did! Thank you very much. Thank you!

Show 1 more comment

1 answer

1


So I’m using the components called Customvalidator and Updatepanel, remembering that there are some rules to insert Updatepanel, if you need more details just ask: Webform1.aspx:

<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" >

    <ContentTemplate>
        <asp:TextBox runat="server" AutoPostBack ="true" ID="dataini"></asp:TextBox>
        <asp:TextBox runat="server" AutoPostBack ="true" ID="datafim" OnTextChanged="datafim_TextChanged"></asp:TextBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator"  OnServerValidate="CustomValidator1_ServerValidate" ></asp:CustomValidator>
     </ContentTemplate>   

   </asp:UpdatePanel>
</div>

here is at Behind: Webform1.aspx.Cs

    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        DateTime dtini = Convert.ToDateTime(dataini.Text);
        DateTime dtfim = Convert.ToDateTime(datafim.Text);
        if (dtini < dtfim)
        {
            CustomValidator1.Text = "Correto";
            CustomValidator1.IsValid = true;

        }
        else
        {
            CustomValidator1.IsValid = false;
            CustomValidator1.Text = "Incorreto";
        }
    }

    protected void datafim_TextChanged(object sender, EventArgs e)
    {
        ServerValidateEventArgs svea = new ServerValidateEventArgs("",true);
        CustomValidator1_ServerValidate(sender,svea);
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.