# Cannot set a custom error message

**URL:** <https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912>\
**Category:** Lead Capture Tools\
**Created:** [December 28, 2022, 1:47pm UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912 "2022-12-28T13:47:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![birdman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/birdman/32/5619_2.png) [@birdman](https://community.hubspot.com/u/birdman)\
**Post date:** [December 28, 2022, 1:47pm UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912/1 "2022-12-28T13:47:23Z")

</div>

I am trying to set a custom error message on a form but so far unsuccessful.

I have created a HubSpot form, set as raw HTML, embedded it on page (using hbspt.forms.create()), and added custom field validators in JavaScript that are correctly being registered with a callback function and triggered. All this works.

When a specific validation is false, how do I set a custom error message?

The method setCustomValidity(“error message”) does not seem to work, nor does ‘textContent’.

---

<div class="post-metadata">

**Author:** ![DianaGomez](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dianagomez/32/48035_2.png) [@DianaGomez](https://community.hubspot.com/u/DianaGomez)\
**Post date:** [December 28, 2022, 6:25pm UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912/2 "2022-12-28T18:25:42Z")

</div>

Hi @birdman, hope you are doing well!

I have found [this thread](https://community.hubspot.com/t5/HubSpot-Ideas/Customize-Error-Message-in-Forms/idi-p/291693) with several options you can try to accomplish your goal.

Hope this helps,

Diana

---

<div class="post-metadata">

**Author:** ![birdman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/birdman/32/5619_2.png) [@birdman](https://community.hubspot.com/u/birdman)\
**Post date:** [December 29, 2022, 9:40am UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912/3 "2022-12-29T09:40:18Z")

</div>

Hi @EDia - I have seen the article before but contains dead links. Do you know the solution? Best Martin

---

<div class="post-metadata">

**Author:** ![DianaGomez](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dianagomez/32/48035_2.png) [@DianaGomez](https://community.hubspot.com/u/DianaGomez)\
**Post date:** [December 29, 2022, 2:04pm UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912/4 "2022-12-29T14:04:42Z")

</div>

Hi Martin, thanks for letting me know, however when I go there the [first link is this one](https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options), and works fine. Could you double-check? This will be the option available at the moment.

About the second one and third one that are the same one, you are right, those are no longer in the Marketplace for that reason you see a broken page.

Hope this helps clarify.

Best,

Diana

---

<div class="post-metadata">

**Author:** ![birdman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/birdman/32/5619_2.png) [@birdman](https://community.hubspot.com/u/birdman)\
**Post date:** [December 29, 2022, 2:51pm UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912/5 "2022-12-29T14:51:26Z")

</div>

Hello Diane, the first link is all known to me and does not provide a solution to the challenge I am having. Thx anyway

---

<div class="post-metadata">

**Author:** ![birdman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/birdman/32/5619_2.png) [@birdman](https://community.hubspot.com/u/birdman)\
**Post date:** [December 29, 2022, 10:55am UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912/6 "2022-12-29T10:55:37Z")

</div>

When looking at the form customization code (see [https://legacydocs.hubspot.com/docs/methods/forms/advanced\_form\_options](https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options)), I see the option to change error messages. But how does this work for custom validations?

For example, I have a text input field, and there are 4 different validations it needs to pass. The error message that needs to be displayed is dependent on the specific validation.

---

<div class="post-metadata">

**Author:** ![birdman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/birdman/32/5619_2.png) [@birdman](https://community.hubspot.com/u/birdman)\
**Post date:** [December 30, 2022, 11:17am UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912/7 "2022-12-30T11:17:40Z")

</div>

I have created a project on GitHub that shows how to create custom form field validations using JavaScript (without jQuery) for those interested. See [GitHub - birdmeister/hubspot-form-validation: Example of how to validate HubSpot form fields with JavaScript · GitHub](https://github.com/birdmeister/hubspot-form-validation)  
Any remarks, corrections and additions are more then welcome.

---

<div class="post-metadata">

**Author:** ![DianaGomez](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dianagomez/32/48035_2.png) [@DianaGomez](https://community.hubspot.com/u/DianaGomez)\
**Post date:** [December 30, 2022, 1:52pm UTC](https://community.hubspot.com/t/cannot-set-a-custom-error-message/71912/8 "2022-12-30T13:52:05Z")

</div>

Hi @birdman 😊

¡Fantastic! Thanks for sharing 😊

Best,

Diana
