Password Check / jQuery /

by asdf

HTML

<div>
	<label for = "pass">Enter your password:</label>
    <input type="password" id = "pass" name = "pass" />
    <span id = "msg"></span>
</div>

JavaScript

(function ($) {
	function isValid (str) {
		var vowels = {
			"a": "",
			"e": "",
			"i": "",
			"o": "",
			"u": ""
		};
		var hasVowels = false,
			vowelsCount = 0,
			consCount = 0;
		for (var i = 0; i < str.length; i++) {
			if (vowels.hasOwnProperty(str[i])) {
				hasVowels = true;
				vowelsCount ++;
				consCount = 0;
			} else {
				consCount ++;
				vowelsCount = 0;
			}
			if (vowelsCount >= 3 || consCount >= 3) {
				return false;
			}
			if (i>0 && str[i] == str[i-1] && (str[i] != 'e' && str[i] != 'o')) {
				return false;
			}
		}
		if (!hasVowels) {
			return false;
		}
		return true;
	}	// end of init
	$.fn.passCheck = function (msgEl) {
        $(this).on('input propertychange', function() {
			var valid = isValid($(this).val());
			if (valid) {
				msgEl.text('Success');
			} else {
				msgEl.text('Failure');
			}
		});
  	};
})(jQuery);

$(document).ready(function(){
	$('#pass').passCheck($('#msg'));
});