validations to check date field within last 12 months

Certified Associate Developer

when a user inputs the date in date field other than within last 12 months then validation error should popup.. Thanks for your time and help..

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Hi Prasad,

    Try this:

    a!localVariables(
      local!date,
      a!formLayout(
        label: "Example: Date Field Validation Rule",
        contents:{
          a!dateField(
            label: "Select a valid date",
            instructions: "Enter a date within last 12 months",
            value: local!date,
            saveInto: local!date,
            validations: {
              if(
                not(
                  and(
                    today() - 365 <= todate(local!date),
                    local!date <= today()
                  )
                ),
                "Date selected is not within last 12 months",
                ""
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Submit",
            submit: true
          )
        )
      )
    )

Reply
  • +1
    Certified Lead Developer

    Hi Prasad,

    Try this:

    a!localVariables(
      local!date,
      a!formLayout(
        label: "Example: Date Field Validation Rule",
        contents:{
          a!dateField(
            label: "Select a valid date",
            instructions: "Enter a date within last 12 months",
            value: local!date,
            saveInto: local!date,
            validations: {
              if(
                not(
                  and(
                    today() - 365 <= todate(local!date),
                    local!date <= today()
                  )
                ),
                "Date selected is not within last 12 months",
                ""
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Submit",
            submit: true
          )
        )
      )
    )

Children