Jump to content

Count number of lowercase/uppercase/numbers in a string?


TheFilmGod

Recommended Posts

How do I use javascript to count the number characters/lowercase/uppercase/numbers of the string "pass"?

 

        var pass = document.basic.password.value;

$chars = # of characters
$l_let = # of lower letters
$u_let # of upper letters
$num = # of numbers

How bout this?

 

<script>
  var pass = document.basic.password.value;
  var chars = pass.length;
  var l_let = pass.match(/[a-z]/g).length;
  var u_let = pass.match(/[A-Z]/g).length;
  var num = pass.match(/\d/g).length;
  alert(
    "# Chars:   "+chars+"\n"+
    "# Lower:   "+l_let+"\n"+
    "# Upper:   "+u_let+"\n"+
    "# Numbers: "+num
  );
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.