> For the complete documentation index, see [llms.txt](https://help.cosmobots.io/help/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.cosmobots.io/help/outros/dicas/validar-data-de-nascimento.md).

# Validar idade

1- Para isso, crie uma mensagem que pergunte a data de nascimento do usuário e salve a resposta como context.data:

![](/files/-Mid-iqif8nAMMW3XMXg)

{% hint style="info" %}
Caso não tenha esse campo em sua lista de opções crie um novo campo.

OBS: Esse exemplo serve para datas no formato dd/mm/aaaa
{% endhint %}

3- Crie uma etapa javaScript e insira o seguinte código:

```

function getAge(dateString) {
    var today = new Date();
    var birthDate = new Date(dateString);
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;
    }
    return age;
}


var date=context.data
var formatDate=date && date.split('/').reverse().join('/')
if(getAge(formatDate)>18){
   context.resposta="ok"
}else{context.resposta="nok"}
console.log(getAge(formatDate))


```

4- Crie um Filtro, e no filtro coloque a seguinte condição e salve:

![](/files/-MickpMn54vAEAVy7BOB)

5- Do lado não do filtro, insira a mensagem que deve ser enviada ao usuário caso ele seja menor que 18 anos:

![](/files/-MicksF605LWVrYPzmrL)

6- Depois crie uma etapa existente e direcione novamente a etapa que pergunta a idade ou para a etapa que você preferir.

![](/files/-MickvFSY3YcePCTxNrR)

7- Prontinho, se o usuário for menor que 18 anos ele vai receber uma mensagem e será encaminhado para perguntar novamente:

![](/files/-MidKtX2DfoBSGZZK9Fj)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.cosmobots.io/help/outros/dicas/validar-data-de-nascimento.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
