I know this is a little late to the game but this does add more to validation and I found it to be very helpful. Sometimes conflicting javascript/jQuery Plugin/API references (eg:searchMeme.js) that reference other jquery versions can cause problems so I create unique bundles for account login actions. These are the steps I would take:
1. Create a separate layout ~/Views/Shared/_AccountLayout.cshtml for AccountController.cs.
2. Create new ~/Account/_ViewStart.csthml with:
@{
Layout = "~/Views/Shared/_AccountLayout.cshtml";
}
3. Create two bundles for css & js in BundleConfig.cs for AccountController:
bundles.Add(new StyleBundle("~/Content/accountcss").Include(
"~/Content/site.css",
"~/Content/bootstrap.css",
"~/Content/font-awesome.css")); /*if using font-awesome */
bundles.Add(new ScriptBundle("~/bundles/accountjs").Include(
"~/Scripts/jquery-1.10.2.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery.validate.unobtrusive.js",
"~/Scripts/bootstrap.js"));//must be after jquery validate
4. Reference the bundles in both ends of head & body in _AccountLayout.cshtml as such:
<title>@ViewBag.Title</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/accountcss")
@Scripts.Render("~/bundles/modernizr")
@this.RenderSection("MetaContent", false)
@this.RenderSection("Styles", false)
</head>
@Scripts.Render("~/bundles/accountjs")
@this.RenderSection("Scripts", false)
</body>
*NOTE: Make sure bootstrap is after jqueryval in bundle
5. Make sure you have @Html.ValidationMessageFor
for each input field within ~/Account/Login.cshtml, ~/Account/Register.cshtml, etc... respectively.
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" })
</div>
</div>
6. Use DataAnnotations to create additional custom validation errors [RegularExpression(@"^([\w]{2,20})@?([\w]{2,20}).?[a-zA-Z]{2,3}$", ErrorMessage="")]
:
[Required(ErrorMessage = "*Username is required."), RegularExpression(@"^[\w+]{3,10}\s?([\w+]{3,15})$", ErrorMessage = "*Username can only be Alphanumeric"),StringLength(25, ErrorMessage = "The {0} must be at least {2} characters long and no bigger than {1} characters.", MinimumLength = 5)]
public string UserName { get; set; }
7. (optional) Lastly, if you changed the DataAnotation for Password then you MUST also change the Password Policy in ~/App_Start/IdentityConfig.cs as such:
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireNonLetterOrDigit = false,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true,
};
8. (optional) Also, check out this article on Roles etc..