# Device settings validation

**URL:** <https://community.homey.app/t/device-settings-validation/73478>\
**Category:** Developers\
**Created:** [December 12, 2022, 9:37am UTC](https://community.homey.app/t/device-settings-validation/73478 "2022-12-12T09:37:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gol](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gol/32/34726_2.png) [@gol](https://community.homey.app/u/gol)\
**Post date:** [December 12, 2022, 9:37am UTC](https://community.homey.app/t/device-settings-validation/73478/1 "2022-12-12T09:37:15Z")

</div>

Only example I can find, in the SDK description, regarding using pattern for validation of device settings is [a-zA-Z].

Has anyone managed to find a pattern for validation of for instance an ip address? Normal regex doesn’t seems to work.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 12, 2022, 10:43am UTC](https://community.homey.app/t/device-settings-validation/73478/2 "2022-12-12T10:43:43Z")

</div>

> [@gol](#):
>
> Has anyone managed to find a pattern for validation of for instance an ip address? Normal regex doesn’t seems to work.

I’m fairly sure that it will use [`input[pattern]`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern), so a valid JS regexp should work, but there may be some challenges regarding proper escaping.

What’s the “normal regex” that you tried?

---

<div class="post-metadata">

**Author:** ![gol](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gol/32/34726_2.png) [@gol](https://community.homey.app/u/gol)\
**Post date:** [December 12, 2022, 12:19pm UTC](https://community.homey.app/t/device-settings-validation/73478/3 "2022-12-12T12:19:30Z")

</div>

@robertklep, Thanks for your reply.  
After some more testing I actually, with correct escaping, got it to work.

IP address validation:

```auto
"pattern": "^(?!0)(?!.*\\.$)((1?\\d?\\d|25[0-5]|2[0-4]\\d)(\\.|$)){4}$"

```

But unfortunately, no error message is displayed if validation fails, so for a better UX-experience it’s probably better to do the validation in onSettings() instead:

```auto
 onSettings(event) {

    // Validate
    const regExIp = new RegExp('^(?!0)(?!.*\\.$)((1?\\d?\\d|25[0-5]|2[0-4]\\d)(\\.|$)){4}$');
    if (!regExIp.test(event.newSettings['host'])) throw new Error('Invalid IP adress!');

```
