Question

In my MVC application, email validation is working perfectly locally but when I m publishing and deploying to server It won't work. I have compared the html source of both local and deployed files and there is no difference. My Razor view mark up is

 <li>
        <p><strong>Email: </strong>@Model.CurrentEmailAddress <span class="deliverychange" onclick="showHidden('emailchange');">(Change email)</span></p>
        <div id="emailchange" class="fullborder" style="display: none;">
            <div class="orderrow newemailaddress">
                @Html.LabelFor(m => m.UpdatedEmailAddress)
                @Html.TextBoxFor(m => m.UpdatedEmailAddress, new { @onkeypress = "showEmailChangeConfirmation();" })
                @Html.ValidationMessageFor(m => m.UpdatedEmailAddress)
            </div>

            <div id="updatedemailkeypress" style="display: none;">
                <div class="orderrow checkboxrow emailchangeconfirm">
                    @Html.LabelFor(m => m.UpdateEmailAddress)
                    @Html.EnumRadioButtonFor(m => m.UpdateEmailAddress, false)
                </div>
            </div>

            <div class="clear">&nbsp;</div>
        </div>
    </li>

and my model is as

    [DataType(DataType.EmailAddress)]
    [RegularExpression(@"^([\w.-]+)@([\w-]+)((.(\w){2,3})+)$", ErrorMessage = "Email is not valid")]
    [Display(Name = "Enter new email address: ")]
    public string UpdatedEmailAddress { get; set; }


    [Display(Name = "We will use ****")]
    public YesNo UpdateEmailAddress { get; set; }
Was it helpful?

Solution 3

After spending a lot of time on this I found the publish wizard is not copying the jquery.validate-vsdoc.js to the scripts folder. I manually copied this to the server and all started working.

OTHER TIPS

Please recheck that form tag is there.

Form validation works actually by validating form valid method. So, the form is required to be exist.

Hope this helps.

Try to use dataannotationsextensions library, you can download from nuget.

and just add Email attribute to your model like this

using DataAnnotationsExtensions;
        [Required]
        [DataType(DataType.EmailAddress)]
        [Email]
        public string UpdatedEmailAddress { get; set; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top