Answer for Leandro Batista :just a problem with the regex expression.
"use strict"; var dataFromDB = "testal"; $('input[name="tbInput"]').on("change",function(){var charToTest = $(this).val();var howManyChars = charToTest.length;var nrMatches = 0;if(howManyChars !== 0){charToTest = charToTest.charAt(0);var regexp = new RegExp(charToTest,'gi');var arrMatches = dataFromDB.match(regexp);nrMatches = arrMatches ? arrMatches.length : 0;}$('#result').html(nrMatches.toString()); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div class="main">What do you wanna count <input type="text" name="tbInput" value=""><br />Number of occurences = <span id="result">0</span></div>