0

I am using MVC Foolproof validation package (https://foolproof.codeplex.com/) to verify if the alias is the same as what was entered for the username. For this i have created a custom validation class and i am using the NotEqualTo attribute like so on my properties

    [Display(Name = "Choose a username*")]
    public string Username { get; set; }

    [Display(Name = "Choose an alias*")]
    [NotEqualTo("Username", ErrorMessage = "alias is the same as username")]
    public string Alias{ get; set; }

on my form i have the flowing for the input

    <div class="form-group">
        @Html.LabelFor(m => m.Alias, new { @class = "has-tooltip", aria_describedby = "alias" })
        <div class="tooltip">
            <i class="icon-info tooltip-toggle"></i>
            <span class="tooltip-content" id="alias" role="tooltip">@Model.AliasHelpText</span>
        </div>
        @Html.TextBoxFor(m => m.Alias, new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.Alias)
    </div>

    <div class="form-group">
        @Html.LabelFor(m => m.Username, new { @class = "has-tooltip", aria_describedby = "username" })
        <div class="tooltip">
            <i class="icon-info tooltip-toggle"></i>
            <span class="tooltip-content" id="username" role="tooltip">@Model.UsernameHelpText</span>
        </div>
        @Html.TextBoxFor(m => m.Username, new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.Username)
    </div>   

When i input the exact same value (same case) in both the username and the alias the validation error message on the alias is triggered. However, when i enter the same value but with different casing e.g.

  • username: myusername
  • alias: Myusername

The validation doesn't trigger. How can i make this possible on the UI please? I have come across jquery.validator.addmethod but im struggling to understand it.

Thanks in advance

Sparky
  • 98,165
  • 25
  • 199
  • 285
Paul
  • 620
  • 11
  • 35
  • You will need to create your own validation attribute that implements `IClientValidatable` and write your own scripts to add the methods to the `$.validator` - refer [The Complete Guide To Validation In ASP.NET MVC 3 - Part 2](http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-2) –  Feb 23 '17 at 21:13
  • Hi @stephen, thanks for the response ill check out the link and see whether i can work something out. Will let you know :) – Paul Feb 23 '17 at 21:37

0 Answers0