Skip to content

Instantly share code, notes, and snippets.

@peterjurkovic
Last active October 27, 2015 10:40
Show Gist options
  • Save peterjurkovic/3a2be8a62669380a0043 to your computer and use it in GitHub Desktop.
Save peterjurkovic/3a2be8a62669380a0043 to your computer and use it in GitHub Desktop.
Uppercase & lowercase & symbol counter
var StringUtils = (function(){
var doCount = function(value, regex){
var i,count=0,len=value.length;
for(i=0;i<len;i++) {
if(regex.test(value.charAt(i))) {
count++;
}
}
return count;
},
countUpperCase = function(value){
return doCount(value, /[A-Z]/);
},
countLowerCase = function(value){
return doCount(value, /[a-z]/);
},
countDigits = function(value){
return doCount(value, /[0-9]/);
},
countSymbols = function(value){
return doCount(value, /[`!"\$%\^&\*\(\)_\-\+={\[}\]:;@'~#\\\|\<,>\.\?\/]/);
};
return {
countUpperCase : countUpperCase,
countLowerCase : countLowerCase,
countSymbols : countSymbols,
countDigits : countDigits
};
}());
StringUtils.countSymbols("`!sdfg\"$%^&dgf*()_-dfgsdfg+={[}]:;@'~#|\<,>.?/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment