# format

Source: https://zotonic.com/docs/1747/format

URI: https://zotonic.com/id/1747

Language: en



Regular expression test.

Checks if an input element’s value matches a regular expression. There is an optional `negate` argument to validate only when the regular expression does not match.

For example, to test a dutch postal code:

```django
<input type="text" id="postcode" name="postcode" value="" />
{% validate id="postcode" type={format pattern="^[0-9][0-9][0-9][0-9] +[A-Za-z][A-Z][a-z]$"} %}
```

Another example, no digits allowed:

```django
<input type="text" id="nodigit" name="nodigit" value="" />
{% validate id="nodigit" type={format pattern="[0-9]" negate} %}
```

Arguments
---------

| Argument          | Description                                                                      | Example                              |
| ----------------- | -------------------------------------------------------------------------------- | ------------------------------------ |
| `pattern`         | The regular expression to match against.                                         | `pattern="[0-9][a-z]+"`              |
| `negate`          | Specify negate when you want to accept values that do not match the pattern.     | `negate`                             |
| `failure_message` | Message to show when the input value does not match the pattern (or does match the pattern when the negate argument is given). Defaults to “Not valid.” | `failure_message="Invalid postcode"` |

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1747?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1747?language=en>)
