Introduction:
Below jQuery code allows to restrict user to enter any specific word
only once in textbox. For demo, I have used "article" word and it should
occur only once in textbox. The code also makes case insensitive
search.
Example:
$(document).ready(function () {
$('#txtDesc').bind('keyup', function () {
var txtToMatch = /article/gi;
var iLimit = 1;
var sMatch = $(this).val().match(txtToMatch);
if (sMatch !== null && sMatch.length > iLimit) {
$(".error").html("The word 'article' can occur only once.");
} else {
$(".error").html("");
}
});
});
0 comments :
Post a Comment