JSFiddle - React, Tailwind, and code Playground

by paffffff

HTML

<input type="password" name="pass" id="pass" />
<span id="passstrength"></span>

CSS

.ok {
			color: green;
		}
		.alert {
			color: orange;
		}
		.error {
			color: red;
		}

JavaScript

jQuery(document).ready(function($) {
    $('#pass').keyup(function(e) {
         var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$", "g");
         var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
         var enoughRegex = new RegExp("(?=.{6,}).*", "g");
         if (false == enoughRegex.test($(this).val())) {
         		$('#passstrength').attr('class', false);
                 $('#passstrength').html('Маловато будет');
         } else if (strongRegex.test($(this).val())) {
                 $('#passstrength').attr('class', 'ok');
                 $('#passstrength').html('Хороший пароль!');
         } else if (mediumRegex.test($(this).val())) {
                 $('#passstrength').attr('class', 'alert');
                 $('#passstrength').html('Средненько!');
         } else {
                 $('#passstrength').attr('class', 'error');
                 $('#passstrength').html('Хреново!');
         }
         return true;
    });
});