# Indexing @handles

## Building an indexer

These instructions explain the protocol logic and instructions for extracting and validating names so you can properly index them and determine the first instance of each name.

***

### Fetch the data

These instructions assume you have access to the entire ordinals data structure with basic details like content type, ID, as well as the content.

Validate that the inscription's content type is any of these:&#x20;

* text/plain
* application/JSON

Fetch text as the raw text contents of an inscription. For example, the text would be the raw contents returned at [https://ordinals.com](https://ordinals.com/content/8071eff74cfa709e9ef2802a9fc78b6fe8ba224c1ef77a62447b6095d26f0f28i0)

###

### Extracting the name from JSON5

Validate the text according to the JSON5 standard.&#x20;

To check if the inscription is JSON, try parsing the text. \
If an error is thrown (invalid JSON), extract the plain text using the ruleset under "Validate Names".

#### Check that the JSON has the required keys:

* p equals "@handles"&#x20;
* op equals "data"&#x20;
* name is present and is type string

Once the name is extracted, follow the steps and proceed to the Validate names steps.

###

### Validate names

* Validate that the string begins with an @
* Validate accepted characters: \
  (Letters (English), Numbers, Underscore (\_), and hyphens (-) only
* Validate length is between 2 and 21 characters (to include the @)
* Turn the string into lowercase&#x20;
* Delete everything after the first whitespace or newline (\n)&#x20;
* Trim all whitespace and newlines
