> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/form/.limitval.md).

# .limitVal()

## **`$(selector).limitVal(maxLength)`**

#### **Description**

Limits the number of characters a user can type into an `<input>` element **in real-time**.

#### Example

```html
<input id="username" />
```

```js
$('#username').limitVal(5);
```

💡 Now the user cannot type more than 5 characters.

### Use cases

Use `.limitVal()` to:

* Restrict short identifiers, such as a verification code.
* Limit a form field to the length accepted by a backend.
* Keep compact inputs within a fixed UI layout.

### More examples

Limit a six-digit verification code:

```html
<input id="verification-code" />
```

```javascript
$('#verification-code').limitVal(6);
```

Limit an account name to 20 characters:

```html
<input id="account-name" />
```

```javascript
$('#account-name').limitVal(20);
```
