Last active
October 27, 2015 10:40
-
-
Save peterjurkovic/3a2be8a62669380a0043 to your computer and use it in GitHub Desktop.
Uppercase & lowercase & symbol counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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