Validation lecture question

In the “validation” lecture it is said that different browsers will display the error message differently, but is it possible for me to customize the error message that I want to show for the user?
https://www.codecademy.com/courses/learn-html/lessons/htm

Hi there,

I did some digging for you. This can be done via JavaScript or directly through HTML. (I’m not quite sure which way is the preferred method–perhaps it’ll come up in a future lesson?) As this is an HTML question, I will leave an example for that here, but if you’re interested in looking into it more, just search .setCustomValidity

HTML:

<input type="number" name="guess" id="guess" required
        oninvalid="setCustomValidity('Enter error message here')"
        oninput="setCustomValidity('')"> --This line's important to remember; it remains blank

Thank you very much that was so helpful, appreciated a lot!

1 Like