# Textbox Length Validation

This sample demonstrates how to validate the length of text entered by a user. The button is disabled until at least 2 characters are entered. OnEnter will not reload the dynamic until the test matches the length.

```powershell
New-UDCard -Title "Search" -Style @{height = 850 } -Content {
    New-UDTextbox -Id 'UsernameBox' -Label "Initials or Name" -OnEnter {
        if ($EventData.Length -gt 2)
        {
            Sync-UDElement -Id 'SearchForUserValidationID'
        }
    } -OnChange {
        $Disabled = (Get-UDElement -Id 'UsernameBox').value.Length -lt 2
        Set-UDElement -Id 'search' -Properties @{
            disabled = $Disabled
        }
    }
    New-UDButton -OnClick {
        Sync-UDElement -Id 'SearchForUserValidationID'
    } -Text "Search" -Id 'search' -Disabled
    
    New-UDDynamic -Id 'SearchForUserValidationID' -Content {
        $UsernameBoxValue = (Get-UDElement -Id 'UsernameBox').value
        New-UDTypography $UsernameBoxValue
    } -LoadingComponent {
        New-UDProgress
        New-UDTypography -Text "Loading users..."
    }

}

```


---

# Agent Instructions: 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:

```
GET https://docs.powershelluniversal.com/v4-beta/samples/apps/textbox-length-validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
