Tell if all characters in a string are same - Javascript jQuery

Javascript examples for jQuery:String

Description

Tell if all characters in a string are same

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.6.1.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from  www  . j ava 2  s.c  om*/
var pwList = ['foo','bar','ffff','dddd','ddaddd'];
for (var p = 0; p < pwList.length; p++){
    var pw = pwList[p];
    $('<p>').text(pw + ': ' + (/^(.)\1+$/.test(pw) ? 'repeated' : 'non-repeated')).appendTo('body');
}
    });

      </script> 
 </head> 
 <body>  
 </body>
</html>

Related Tutorials