I'm creating an MVC page that uses Kendo validation.

I have the following Model:

public class ForgotPasswordModel
{
    [Required(ErrorMessage = " ")]
    public string UserName { get; set; }

    [Required(ErrorMessage = " ")]
    [EmailAddress(ErrorMessage = " ")]
    public string Email { get; set; }

    public string PhoneNumber { get; set; }

    [Required(ErrorMessage = " ")]
    public string Code { get; set; }
}

I do not want my view to show Error Message for the Email field. I want it to show only exclamation sign when validation fails.

Currently I have the following code in my View:

@model Site.Models.ForgotPasswordModel

@{
    ViewBag.Title = "Forgot Password";
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>

    <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />

    <script src="~/Scripts/jquery-3.1.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>

    <link href="~/Content/kendo/kendo.common-material.min.css" rel="stylesheet" />
    <link href="~/Content/kendo/kendo.custom.css" rel="stylesheet" />
    <link href="~/Content/kendo/custom.css" rel="stylesheet" />

    <script src="~/Scripts/kendo/kendo.all.min.js"></script>
    <script src="~/Scripts/kendo/kendo.aspnetmvc.min.js"></script>


    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

    <style>
        input[type=text]::-ms-clear {
            display: none;
        }

        input[type=password]::-ms-reveal {
            display: none;
        }

        .errMsg {
            font-weight: bolder;
            color: red;
        }

        span#UserName_validationMessage, span#Email_validationMessage,span#Code_validationMessage  {
            display: inline-block;
            width: 160px;
            text-align: left;
            border: 0;
            padding: 0;
            margin: -20px;
            background: none;
            box-shadow: none;
            color: red;
        }

        .k-invalid-msg {
            display: none;
        }
    </style>

</head>
<body>
    <div> 
    </div>
    <div style="margin-top: 20px;">
        <div style="margin: 0 auto; width: 940px; height: 409px; background-image: url('../../Content/images/finance-globe.jpg');"/>
            @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "ForgotPasswordForm" }))
            {
                <div style="margin: 0 auto; margin-top: 20px;">
                    <table id="ForgotPassword" style="margin: 0" auto;">
                        <tr style="height:40px;">
                            <td>@Html.EditorFor(x => x.UserName, new { htmlAttributes = new { @class = "form-control k-textbox checkError", placeholder = "username" } })</td>
                        </tr>
                        <tr style="height:40px;">
                            <td>@Html.EditorFor(x => x.Email, new { htmlAttributes = new { @class = "form-control k-textbox checkError", placeholder = "email" } })</td>
                        </tr>
                        <tr style="height:40px;">
                            <td>@Html.EditorFor(x => x.PhoneNumber, new { htmlAttributes = new { @class = "form-control k-textbox", placeholder = "phone number" } })</td>
                        </tr>
                        <tr style="height:40px;">
                            <td>@Html.EditorFor(x => x.Code, new { htmlAttributes = new { @class = "form-control k-textbox checkError", placeholder = "code" } })</td>
                        </tr>
                    </table>
                </div>
            }
    </div>
</body>
</html>

<script>
    $(document).ready(function () {
        $("#ForgotPasswordForm").kendoValidator();
    });
</script>

The Model and View produce the following:

enter image description here

I do not want "Email is not valid" message to be displayed in case of regular expression validation fails.

I just need an exclamation sign.

How can I do that?

1

There are 1 best solutions below

0
On

For your email field you can try adding data-email-msg attribute, which is way to customize the validation message for wrong email field value.

For ex: If you want to display a blank message for wrong value for email id you can do something like:

<input type="email" name="email" id="email" name="email" data-email-msg="">

And if you want to customize the required field validation message too, then you can add an another attribute data-required-msg as below:

<input type="email" name="email" id="email" name="email" data-email-msg="" data-required-msg="">