Created
November 20, 2021 10:10
-
-
Save reachkamrul/eb4930ae83294e50ba4dbe8356033932 to your computer and use it in GitHub Desktop.
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
ThisForm = $('.maxChar'); // Give element class | |
min = 5; //Give minimum character number | |
max = 10; //Give maximum chartacter number | |
limitCrossed = "you have reached the limit"; // Text to show when limit crossed | |
goodToGo = "good to go"; // Text to show when the character length is perfect, use " " if you dont want to show any text | |
required = "characters required"; // Text to show minimum character required | |
ThisForm.after( "<p class='charLimit'></p>" ); | |
ThisForm.on('keyup keypress',function () { | |
$(this).attr('maxlength',max) | |
$(this).attr('minlength',min) | |
var len = $(this).val().length; | |
if (len == 10) { | |
$('.charLimit').html(' '+limitCrossed); | |
} | |
if (min-1<len && len<max) { | |
$('.charLimit').text(goodToGo); | |
} | |
if(len<min) { | |
var char = min - len; | |
$('.charLimit').text(char + ' '+required); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment