# Native way to get if an input is not valid?

**URL:** <https://community.weweb.io/t/native-way-to-get-if-an-input-is-not-valid/17020>\
**Category:** How do I?\
**Tags:** design\
**Created:** [March 6, 2025, 1:29am UTC](https://community.weweb.io/t/native-way-to-get-if-an-input-is-not-valid/17020 "2025-03-06T01:29:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilles974](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/gilles974/32/12803_2.png) [@gilles974](https://community.weweb.io/u/gilles974)\
**Post date:** [March 6, 2025, 1:29am UTC](https://community.weweb.io/t/native-way-to-get-if-an-input-is-not-valid/17020/1 "2025-03-06T01:29:29Z")

</div>

Hello,

I’m coming from Bubble where we can get a “when input’s value isn’t valid” (for example for an email address input).

I’ve been trying multiple ways on WW to get this but I couldn’t figure it out. I’d like to dynamically display the text color of the input (red if not valid, for example not an email address). How do you do it?

Here’s one of the things I’ve tried but it won’t work.

 ![Screenshot 2025-03-06 at 09.30.42](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/6/6d5bf4d27f000887abcdc867982cf70ca3fd2fbe.png)

Thanks!

---

<div class="post-metadata">

**Author:** ![joaosander](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joaosander/32/12584_2.png) [@joaosander](https://community.weweb.io/u/joaosander)\
**Post date:** [March 6, 2025, 5:42am UTC](https://community.weweb.io/t/native-way-to-get-if-an-input-is-not-valid/17020/2 "2025-03-06T05:42:51Z")

</div>

> [@gilles974](#):
>
> Thanks!

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/b/b42ef58da45c95b10602daf89603956c9d8a66a9.png)

it should work, i don’t know why isValid is returning null, maybe a bug

After a few tests i saw that “required” and input type “email” doesnt change isValid value to true or false, it just send a little error message, maybe in future it will be changed 😃

Also isValid is just changed after u submit the form

---

<div class="post-metadata">

**Author:** ![gilles974](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/gilles974/32/12803_2.png) [@gilles974](https://community.weweb.io/u/gilles974)\
**Post date:** [March 6, 2025, 6:53am UTC](https://community.weweb.io/t/native-way-to-get-if-an-input-is-not-valid/17020/3 "2025-03-06T06:53:40Z")

</div>

I also tried to create a custom state with a JS

```auto
function isValidEmail(email) {
    // A basic regex pattern to validate the email format.
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return emailRegex.test(email);
}

// Suppose this variable might contain quotes, etc.
const variable = context.thisInstance?.['_value'];

// If you're sure it's a string, just assign it:
// const email = variable;

// Or ensure it's a string (without adding extra quotes):
const email = String(variable);

if (isValidEmail(email)) {
    // console.log("Valid email format");
    return true;
} else {
    // console.log("Invalid email format");
    return false;
}

```

But it won’t render my color based on this new custom state. I really don’t know why.
