# API Token Length

**URL:** <https://devforum.okta.com/t/api-token-length/5519>\
**Category:** Questions\
**Created:** [June 30, 2019, 4:04pm UTC](https://devforum.okta.com/t/api-token-length/5519 "2019-06-30T16:04:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmcnabb](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mmcnabb/32/321_2.png) [@mmcnabb](https://devforum.okta.com/u/mmcnabb)\
**Post date:** [June 30, 2019, 4:04pm UTC](https://devforum.okta.com/t/api-token-length/5519/1 "2019-06-30T16:04:38Z")

</div>

Are API tokens always the same length? I’d like to validate user input of API tokens before attempting to authenticate, and wanted to make sure of this before I attempt it. Thanks!

---

<div class="post-metadata">

**Author:** ![dragos](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/dragos/32/1313_2.png) [@dragos](https://devforum.okta.com/u/dragos)\
**Post date:** [July 1, 2019, 2:02am UTC](https://devforum.okta.com/t/api-token-length/5519/2 "2019-07-01T02:02:34Z")

</div>

Hi @mmcnabb

Yes, the API tokens are always 42 characters in length. You can use a regular expression like the following to match them `^00[a-zA-Z0-9\-\_]{40}$` .

---

<div class="post-metadata">

**Author:** ![mmcnabb](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mmcnabb/32/321_2.png) [@mmcnabb](https://devforum.okta.com/u/mmcnabb)\
**Post date:** [July 1, 2019, 2:25am UTC](https://devforum.okta.com/t/api-token-length/5519/3 "2019-07-01T02:25:41Z")

</div>

> [@dragos](#):
>
> ^00[a-zA-Z0-9-\_]{40}$

Thanks, that’s exactly what I was looking to do!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [January 23, 2024, 7:13pm UTC](https://devforum.okta.com/t/api-token-length/5519/4 "2024-01-23T19:13:32Z")

</div>

Closed on January 23, 2024, 7:13pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
