2014-10-17 68 views
0

我很難找到工作密碼強度檢查程序的方法,但仍未找到解決方案。我在部分視圖中爲一些簡單的輸入提供了AjaxBeginForm。如何在MVC中包含密碼強度驗證程序4

這是我的觀點: @model EntryViewModel

<style> 
input.input-validation-error, 
textarea.input-validation-error, 
select.input-validation-error { 
    background: #FEF1EC; 
    border: 1px solid #CD0A0A; 
} 
.field-validation-error { 
    color: #C55050; 
} 
</style> 


@using (Ajax.BeginForm("Create", "Entry", new AjaxOptions { HttpMethod = "Post" })) 
{ 
    @Html.AntiForgeryToken() 
    @Html.ValidationSummary(true) 

    <div class="editor-label"> 
     @Html.LabelFor(model => model.Title) 
    </div> 
    <div class="editor-field"> 
     @Html.TextBoxFor(model => model.Title, new { @class = "form-control" }) 
     @Html.ValidationMessageFor(model => model.Title) 
    </div> 

    <div class="editor-label"> 
     @Html.LabelFor(model => model.Username) 
    </div> 
    <div class="editor-field"> 
     @Html.TextBoxFor(model => model.Username, new { @class = "form-control" }) 
     @Html.ValidationMessageFor(model => model.Username) 
    </div> 

    <div class="editor-label"> 
     @Html.LabelFor(model => model.Password) 
    </div> 
    <div class="editor-field"> 
     @Html.TextBoxFor(model => model.Password, new { @class = "form-control" }) 
     @Html.ValidationMessageFor(model => model.Password) 
    </div> 

    <div class="editor-label"> 
     @Html.LabelFor(model => model.Url) 
    </div> 
    <div class="editor-field"> 
     @Html.TextBoxFor(model => model.Url, new { @class = "form-control" }) 
     @Html.ValidationMessageFor(model => model.Url) 
    </div> 

    <div class="editor-label"> 
     @Html.LabelFor(model => model.Description) 
    </div> 
    <div class="editor-field"> 
     @Html.TextAreaFor(model => model.Description, new { @class = "form-control" }) 
     @Html.ValidationMessageFor(model => model.Description) 
    </div> 

    @Html.HiddenFor(model => model.CategoryId) 

    <div class="modal-footer"> 
     <a href="#" data-dismiss="modal" class="btn">Close</a> 
     <input class=" btn btn-primary" id="submitButton" type="submit" value="Create" /> 
    </div> 
} 

我有很多方法,包括KendoUI,但沒有作品的嘗試。任何解決方案的建議?

+0

看看這些jQuery的解決方案:http://www.freshdesignweb.com/jquery-password-strength.html – 2014-10-17 16:21:49

回答

1

怎麼樣StringLength和數據類型(DataType.Password)

public class RegisterModel 
{ 
    [Required] 
    [Display(Name = "Name")] 
    public string UserName { get; set; }  

    [Required] 
    [StringLength(100, ErrorMessage = "Pass \"{0}\" must have no less {2} chars.", MinimumLength = 8)] 
    [DataType(DataType.Password)]