# Typed input of type 're' (i.e. regular expresssion)

**URL:** https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891
**Category:** Developing Nodes
**Created:** [13 December 2024 06:50 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891 "2024-12-13T06:50:12Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [13 December 2024 06:50 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/1 "2024-12-13T06:50:12Z")

</div>

Hi folks,

I want to enter a text into a typedinput, but there should be a visible indication when the text does not match a specified regular expression.

I see that the [typedinput](https://nodered.org/docs/api/ui/typedInput/) allows to use regular expressions:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7f740d29f026227009ab6e5fd8198f99e1dfb0b9.png)

Can that be used for my purpose? And could anybody provide a simple example? I certainly must be overthinking it, but I am not sure how to specify my regex...

Thanks!!  
Bart

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [13 December 2024 07:11 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/2 "2024-12-13T07:11:14Z")

</div>

Not quite following Bart. Can you provide an annotated screen shot describing what you are seeing and what you expect to see?

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [13 December 2024 07:57 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/3 "2024-12-13T07:57:16Z")

</div>

Hey Steve,  
I have no screen yet for this part. Currently I have a simple text input element, with a regex to validate the input based on some pattern. For example:

```auto
<input type="text" name="country_code" pattern="[A-Za-z]{3}">

```

Now I would like to do something similar with a TypedInput. So I thought that I could use identifier _ **"re"** _ instead of _ **"str"** _ (see screenshot above).

But from your response I assume the "re" identifier is used for a complete other purpose?

Thanks!

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [13 December 2024 08:12 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/4 "2024-12-13T08:12:48Z")

</div>

So, the `re` input is to provide a means of letting a user enter a regex, not for validating users input.

If you simply want to validate user input you can do that use a validator (you can even use regex in your validation).

```auto
        defaults: {
            myString: {
                value: "",
                validate: RED.validators.regex(/[A-Za-z]{3}/)
            },
            ...
        }

```

Perhaps if you provide context to the task at hand I can better help?

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [13 December 2024 17:03 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/5 "2024-12-13T17:03:59Z")

</div>

> [@Steve-Mcl](#):
>
> the `re` input is to provide a means of letting a user enter a regex

Ah that explains my confusion. Indeed I thought it was used for validating an input based on a regex, and I had no idea where to specify that regex 🙄

So my case is this: some property needs to be a string, that needs to contain a pattern. The string can be hardcoded in the config screen, or injected via an input message. So the types of my TypedInput are `["str", "msg"]`. But in the config screen the pattern matching test should only be applied when type is "str", not for "msg".

While writing my problem down here, I assume you are going to tell me that I need a validation function that only checks the pattern if type is "str"...

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [13 December 2024 17:09 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/6 "2024-12-13T17:09:46Z")

</div>

You can define your own type that is a copy of the `str` type, but with your added custom validation rule:

```auto
types: [
    {
        value: "str",
        label: "Bart's String",
        icon: "red/images/typedInput/az.svg",
        validate: function (value, opt) {
            // return true/false depending on if `value` is valid or not
        }
    },
    'msg'
]

```

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [13 December 2024 17:21 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/7 "2024-12-13T17:21:00Z")

</div>

Ah ok, that is indeed much more readable compare to a general validation function that depends on the type.  
Thanks guys and enjoy your weekend!

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [14 December 2024 09:51 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/8 "2024-12-14T09:51:33Z")

</div>

I add that you can also return a string which will be the error message displayed by the input.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [12 February 2025 09:51 UTC](https://discourse.nodered.org/t/typed-input-of-type-re-i-e-regular-expresssion/93891/9 "2025-02-12T09:51:40Z")

</div>

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