The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

validationMessage property

Returns the error message that would be displayed if the user submits the form, or an empty string if no error message. It also triggers the standard error message, such as "this is a required field". The result is that the user sees validation messages without actually submitting.

This property is read-only.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 4Internet Explorer 10



sMessage = object.validationMessage


Property values

Type: DOMString

Standards information


Returns a string containing the standard or custom error message that would be displayed if the user submitted at this time. If no errors are present or the form would validate, an empty string is returned.

The following example has a required field, and if the user types "fun" into it, a custom message is set. Try previewing without anything in the field, then enter values, including the word fun:

Note  For more code samples, see Form controls part 1 and Form controls part 2: validation on the Windows Internet Explorer sample site.


<form id="myForm">
<label>Type anything but "fun": <input id="noFun" type="text" oninput="checkValid(this)" required ><input type="submit"></label>
<div><button onclick="previewMessage();">Preview errors</button></div>
<div id="err"></div>
    function checkValid(input) {
        if (input.value == "fun") {
            input.setCustomValidity("You're having too much fun!");
        } else {
            // input is fine -- reset the error message
    function previewMessage() {
        var myform = document.getElementById("noFun")
        document.getElementById("err").innerHTML = myform.validationMessage;

See also




© 2014 Microsoft