# Validate what user input in a flow card

**URL:** <https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958>\
**Category:** Developers\
**Tags:** flow, advancedflow\
**Created:** [October 21, 2022, 7:18pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958 "2022-10-21T19:18:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [October 21, 2022, 7:18pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/1 "2022-10-21T19:18:32Z")

</div>

Hi,  
I’m developing Local API App.  
I was wondering if there was a way (a method, or, better, a piece of documented code) to validate the fields entered by users through Flows (normal and advanced).  
My intent is to check that the text fields entered have certain characteristics (simple controls, such as startswith or regex)  
On the documentation I haven’t found anything about it.  
Is there a method to validate what user input in a flow card input?

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 21, 2022, 7:28pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/2 "2022-10-21T19:28:35Z")

</div>

What should be a valid input? JSON in general? Then I would parse the string with JSON.parse() and check if it doesn’t throw an error.  
If it’s free text or could be XML, too, then it’s hard to decide about the content type.  
If you are using content-type in the response, you could add a optional enum field in the flow card where the user can select a content-type (application/json…). And depending that you can parse the content.

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [October 21, 2022, 7:38pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/3 "2022-10-21T19:38:12Z")

</div>

You’re right, sorry, I didn’t make myself clear.

I know how to validate a data that comes to me through a user input, however I would like a function that would allow me to validate it _when saving the Flow_ or _when an input is just written in the flow_, and give me the capability to immediately report the error to the user.

At the moment, if during the creation phase the user enters “invalid” data, the Flow allows it to insert that data because it distinguish between a string or a number, but does not allow me “on the fly” to provide a validations chosen by me (developer) more complex rather then the type of data entered.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 21, 2022, 7:40pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/4 "2022-10-21T19:40:33Z")

</div>

Ah, at flow creation time…  
I don’t think you can interact. That’s default Homey core/GUI and just text fiels.

The only thing you can do is throwing a error in the flow so the User can write the error output to timeline.

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [October 21, 2022, 7:48pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/5 "2022-10-21T19:48:57Z")

</div>

You can add a Regex to validate an user input, but don’t think Regex is extensive(?) enough to validate if the input is valid JSON.

EDIT: hmmm, maybe there is [one big one](https://stackoverflow.com/questions/2583472/regex-to-validate-json) 😅 not sure it will fit the Regex flag though.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 21, 2022, 7:51pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/6 "2022-10-21T19:51:34Z")

</div>

Regex in flow definition to check user input in flow editor?

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [October 21, 2022, 7:53pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/7 "2022-10-21T19:53:21Z")

</div>

Aah never mind… it was for [device settings](https://apps.developer.homey.app/the-basics/devices/settings#text)… I wonder why they didn’t do it for flow cards, or just not documentated .

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [October 21, 2022, 7:59pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/8 "2022-10-21T19:59:35Z")

</div>

Sorry for the spam, but had another idea that might be a bit difficult as it isn’t documented yet, the “code” input field, like HomeyScript uses has a build-in validator, and the code for [HomeyScript is opensource](https://github.com/athombv/com.athom.homeyscript), so perhaps you can take some inspiration there how it is used.

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [October 21, 2022, 8:06pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/9 "2022-10-21T20:06:46Z")

</div>

Thank you @RonnyW and @Caseda

I try to read something, however I would have to find a way to interact directly with the core of the flow part to be able to throw an exception for the user GUI.  
I will keep you updated in case I find something useful.

If anyone has any other ideas, are welcome!

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 21, 2022, 8:07pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/10 "2022-10-21T20:07:12Z")

</div>

I thought you would have some magic things, a rabbit rabbit and a hat 🙂

But yes, the code field sounds nice.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 21, 2022, 8:08pm UTC](https://community.homey.app/t/validate-what-user-input-in-a-flow-card/70958/11 "2022-10-21T20:08:31Z")

</div>

> <https://github.com/athombv/com.athom.homeyscript/blob/master/.homeycompose/flow/actions/runCode.json>

Line 14 you can try in your flow card.
