user5085: I want to check on-chain if a given TokenName is of a specific pattern, for example:

aaa1
aaa2
aaa3

I have something like this, but it throws an interpreter exception:
checkValidMint :: TokenName -> Integer -> Bool
checkValidMint tn count  = tn == (TokenName $ "aaa" <> (integerToByteString count))

integerToByteString :: Integer -> BuiltinByteString
integerToByteString n
    | n == 0 = "0"
    | n == 1 = "1"
    | n == 2 = "2"
    | n == 3 = "3"
    | n == 4 = "4"
    | n == 5 = "5"
    | n == 6 = "6"
    | n == 7 = "7"
    | n == 8 = "8"
    | n == 9 = "9"
    | otherwise = integerToByteString (n `P.divide` 10) P.<> integerToByteString (n `P.modulo` 10)

Update 2
Also tried:
integerToByteString n
            | (Builtins.equalsInteger n 0) = "0"
            | (Builtins.equalsInteger n 1) = "1"
            | (Builtins.equalsInteger n 2) = "2"
            | (Builtins.equalsInteger n 3) = "3"
            | (Builtins.equalsInteger n 4) = "4"
            | (Builtins.equalsInteger n 5) = "5"
            | (Builtins.equalsInteger n 6) = "6"
            | (Builtins.equalsInteger n 7) = "7"
            | (Builtins.equalsInteger n 8) = "8"
            | (Builtins.equalsInteger n 9) = "9"
            | otherwise = integerToByteString (n `PlutusTx.Prelude.divide` 10) PP.<> integerToByteString (n `PlutusTx.Prelude.modulo` 10)

I keep getting an interpreter error:
GHC Core to PLC plugin: E042:Error: Unsupported feature: Use of Haskell Integer equality, possibly via the Haskell Eq typeclass Context: Compiling expr: GHC.Integer.Type.eqInteger# Context: Compiling expr: GHC.Integer.Type.eqInteger# x Context: Compiling expr: GHC.Integer.Type.eqInteger# x y Context: Compiling expr: case GHC.Integer.Type.eqInteger# x y of wild [Occ=Once] { __DEFAULT -> GHC.Prim.tagToEnum# @ GHC.Types.Bool wild } Context: Compiling expr: \ (y [Occ=Once] :: GHC.Integer.Type.Integer) -> case GHC.Integer.Type.eqInteger# x y of ...



user1130: This is how I've done the integer conversion in the past. Might need some minor updating:
{-# INLINEABLE intToString #-}
intToString :: Integer -> Builtins.String
intToString i = Prelude.foldr Builtins.appendString "" strings
  where
    ints = intToInts i
    strings = map (Builtins.charToString . intToChar) ints


{-# INLINEABLE intToChar #-}
intToChar :: Integer -> Haskell.Char
intToChar i
  | (Builtins.equalsInteger i 0) = '0'
  | (Builtins.equalsInteger i 1) = '1'
  | (Builtins.equalsInteger i 2) = '2'
  | (Builtins.equalsInteger i 3) = '3'
  | (Builtins.equalsInteger i 4) = '4'
  | (Builtins.equalsInteger i 5) = '5'
  | (Builtins.equalsInteger i 6) = '6'
  | (Builtins.equalsInteger i 7) = '7'
  | (Builtins.equalsInteger i 8) = '8'
  | (Builtins.equalsInteger i 9) = '9'
  | otherwise = '0' -- Fix this


Then instead of checkValidMint, you can just check that the expected amount of your new token is included in the output value in the policy ctx, like here in the Uniswap example.

5085: <p>I want to check <strong>on-chain</strong> if a given <code>TokenName</code> is of a specific pattern, for example:</p>
<ul>
<li><code>aaa1</code></li>
<li><code>aaa2</code></li>
<li><code>aaa3</code></li>
</ul>
<p>I have something like this, but it throws an interpreter exception:</p>
<pre><code>checkValidMint :: TokenName -&gt; Integer -&gt; Bool
checkValidMint tn count  = tn == (TokenName $ &quot;aaa&quot; &lt;&gt; (integerToByteString count))

integerToByteString :: Integer -&gt; BuiltinByteString
integerToByteString n
    | n == 0 = &quot;0&quot;
    | n == 1 = &quot;1&quot;
    | n == 2 = &quot;2&quot;
    | n == 3 = &quot;3&quot;
    | n == 4 = &quot;4&quot;
    | n == 5 = &quot;5&quot;
    | n == 6 = &quot;6&quot;
    | n == 7 = &quot;7&quot;
    | n == 8 = &quot;8&quot;
    | n == 9 = &quot;9&quot;
    | otherwise = integerToByteString (n `P.divide` 10) P.&lt;&gt; integerToByteString (n `P.modulo` 10)
</code></pre>
<p><strong>Update 2</strong>
Also tried:</p>
<pre><code>integerToByteString n
            | (Builtins.equalsInteger n 0) = &quot;0&quot;
            | (Builtins.equalsInteger n 1) = &quot;1&quot;
            | (Builtins.equalsInteger n 2) = &quot;2&quot;
            | (Builtins.equalsInteger n 3) = &quot;3&quot;
            | (Builtins.equalsInteger n 4) = &quot;4&quot;
            | (Builtins.equalsInteger n 5) = &quot;5&quot;
            | (Builtins.equalsInteger n 6) = &quot;6&quot;
            | (Builtins.equalsInteger n 7) = &quot;7&quot;
            | (Builtins.equalsInteger n 8) = &quot;8&quot;
            | (Builtins.equalsInteger n 9) = &quot;9&quot;
            | otherwise = integerToByteString (n `PlutusTx.Prelude.divide` 10) PP.&lt;&gt; integerToByteString (n `PlutusTx.Prelude.modulo` 10)
</code></pre>
<p>I keep getting an interpreter error:</p>
<pre><code>GHC Core to PLC plugin: E042:Error: Unsupported feature: Use of Haskell Integer equality, possibly via the Haskell Eq typeclass Context: Compiling expr: GHC.Integer.Type.eqInteger# Context: Compiling expr: GHC.Integer.Type.eqInteger# x Context: Compiling expr: GHC.Integer.Type.eqInteger# x y Context: Compiling expr: case GHC.Integer.Type.eqInteger# x y of wild [Occ=Once] { __DEFAULT -&gt; GHC.Prim.tagToEnum# @ GHC.Types.Bool wild } Context: Compiling expr: \ (y [Occ=Once] :: GHC.Integer.Type.Integer) -&gt; case GHC.Integer.Type.eqInteger# x y of ...
</code></pre>
<pre><code></code></pre>
 1130: <p>This is how I've done the integer conversion in the past. Might need some minor updating:</p>
<pre><code>{-# INLINEABLE intToString #-}
intToString :: Integer -&gt; Builtins.String
intToString i = Prelude.foldr Builtins.appendString &quot;&quot; strings
  where
    ints = intToInts i
    strings = map (Builtins.charToString . intToChar) ints


{-# INLINEABLE intToChar #-}
intToChar :: Integer -&gt; Haskell.Char
intToChar i
  | (Builtins.equalsInteger i 0) = '0'
  | (Builtins.equalsInteger i 1) = '1'
  | (Builtins.equalsInteger i 2) = '2'
  | (Builtins.equalsInteger i 3) = '3'
  | (Builtins.equalsInteger i 4) = '4'
  | (Builtins.equalsInteger i 5) = '5'
  | (Builtins.equalsInteger i 6) = '6'
  | (Builtins.equalsInteger i 7) = '7'
  | (Builtins.equalsInteger i 8) = '8'
  | (Builtins.equalsInteger i 9) = '9'
  | otherwise = '0' -- Fix this

</code></pre>
<p>Then instead of <code>checkValidMint</code>, you can just check that the expected amount of your new token is included in the output value in the policy <code>ctx</code>, like <a href="https://github.com/input-output-hk/plutus-apps/blob/c4cc9ee1add8f421e57789befb6a0c90621801f1/plutus-use-cases/src/Plutus/Contracts/Uniswap/OnChain.hs#L105" rel="nofollow noreferrer">here</a> in the Uniswap example.</p>
