> For the complete documentation index, see [llms.txt](https://docs.verygoodsecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/js/formatting.md).

# Formatting

![VGS Collect.js masked input](/files/VVUrsa9lQroiFyzPRg19)

## Serializers

Use serializers to change the format of the data being sent to the server.

*Examples:*

{% code title="Replace value" %}

```javascript
form.field('#space-for-my-field', {
    serializers: [{ name: 'replace', options: { old:' ', new:'-' }}],
    serializers: [{ name: 'replace', options: { old:' ', new:'-', count: '2' }}]
});
```

{% endcode %}

{% code title="Expiration date separator" %}

```javascript
form.field('#space-for-my-field', {
    serializers: [{ name: 'separate', options: { monthName: 'month', yearName: 'year' }}]
});
```

{% endcode %}

{% code title="Convert to base64" %}

```javascript
form.field('#space-for-my-field', {
    type: 'file'
    serializers: [{ name: 'toBase64'}]
});
```

{% endcode %}

* [.field()](/vault/developer-tools/vgs-collect/js/reference-documentation.md#api-formfield)
* [Reference Documentation](/vault/developer-tools/vgs-collect/js/reference-documentation.md)

## Custom masking

An input mask refers to a string expression, defined by a developer, that constrains user input. This method is available for those types of fields: `text`, `textarea`, `password`, `zip-code`.

Example:

```javascript
f.field('#ssn .field-space', {}).mask('999-99-9999', '*');

f.field('#random-mask .field-space', {}).mask('XXXXX', null, {'X': '[0-9]'});
```

* [.mask()](/vault/developer-tools/vgs-collect/js/reference-documentation.md#api-formcardcvcfield-16)
* [Reference Documentation](/vault/developer-tools/vgs-collect/js/reference-documentation.md)

## Define string replace pattern

Method returns a new string with some or all matches of a pattern replaced by a replacement. This method is available for those types of fields: `text`, `textarea`, `password`, `zip-code`.

Example:

```javascript
f.field('#letters-only .field-space', {}).replacePattern('/[^a-zA-Z\s]+/g');

f.field('#numeric-only .field-space', {}).replacePattern('/[^\d]+/g');
```

* [.mask()](/vault/developer-tools/vgs-collect/js/reference-documentation.md#api-formcardcvcfield-16)
* [Reference Documentation](/vault/developer-tools/vgs-collect/js/reference-documentation.md)

## More examples

* [Control expiration date year length](/vault/developer-tools/vgs-collect/js/samples.md#control-expiration-date-year-length)
* [Separate month and year for the card expiration date field](/vault/developer-tools/vgs-collect/js/samples.md#separate-month-and-year-for-the-card-expiration-date-field)
* [Change expiration date separator](/vault/developer-tools/vgs-collect/js/samples.md#change-expiration-date-separator)


---

# 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://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/js/formatting.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.
