Friday, 19 February 2016

How to count a specific character by java script in mvc?

  @Html.TextBoxFor(model => model.TagKeyWord, new { @class = "text", @style = "width:98%", @id = "seotagkeyword", onkeyup = "counttagkeyword(this);" })

<script type="text/javascript">
function counttagkeyword() {
        debugger;
        var area = document.getElementById("seotagkeyword").value;
        var count = (area.match(/,/g) || []).length;  
            alert(count);
    }
</script>

In C#
______________________________
 string character = model.TagKeyWord;
int count = character.Count(x => x == ',');

No comments:

Post a Comment