- home ›
- methods ›
- repetition
- Dom
- click
- inArray
- merge objects
- query string
- smartcheck
- attr
- addClass
- hasClass
- removeClass
- append
- prepend
- remove
- has
- findAll
- empty
- position
- offset
- outerWidth
- outerHeight
- replaceWith
- html
- text
- val
- parseHTML
- parseJSON
- parent
- next
- prev
- first
- last
- now
- toArray
- size
- Manipulation
- dates compare
- getMonthName
- getDayName
- .NET JSON date
- hashtag
- number Format
- pad
- smallCase
- upperCase
- Forms
- focus
- mobile number
- repetition
- placeholder
- Browser
- browser feature
- Browser Information
- Effects
- hide
- show
- sticky
- scrolline
- goUp
- Animation
- circles
- Google analytics
- Google fonts
.repetition()
Description: Validate if a field contains a character that is repeated consecutively more than allowed times.
Example:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>repetition demo</title>
<script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
</head>
<body>
<table cellpadding="10" cellspacing="0" class="blocks">
<tr>
<td width="100" valign="top"><b>Repetition:</b></td>
<td>
<input type="text" name="repetition_field" class="repetition_field" value="BitsyCooode" />
<span class="repetition_field_result"></span>
</td>
</tr>
<tr>
<td></td>
<td><input type="button" name="submit" onclick="repetition();" value="Validate" /></td>
</tr>
</table>
<p><strong>Preview (Multiple Elements):</strong></p>
<table cellpadding="10" cellspacing="0" class="blocks">
<tr>
<td width="100" valign="top"><b>Repetition:</b></td>
<td>
<input type="text" name="repetition_field_1" class="repetition_field_1" value="BitsyCooode" />
<span class="repetition_field_1_result"></span>
</td>
</tr>
<tr>
<td width="100" valign="top"><b>Repetition:</b></td>
<td>
<input type="text" name="repetition_field_2" class="repetition_field_2" value="BitsyCoode" />
<span class="repetition_field_2_result"></span>
</td>
</tr>
<tr>
<td></td>
<td><input type="button" name="submit" onclick="repetitionboth();" value="Validate Both Fields" /></td>
</tr>
</table>
<script>
function repetition() {
var repeated = bitsyCode(".repetition_field").repetition({ min:2 });
repeated = repeated ? "✘ Repetition <b>found</b>." : "✔ <b>No</b> repetition.";
bitsyCode(".repetition_field_result").html(repeated);
}
function repetitionboth(){
var repeated = bitsyCode(".repetition_field_1, .repetition_field_2").repetition({ min:2 });
rep1 = repeated[0] ? "✘ Repetition <b>found</b>." : "✔ <b>No</b> repetition.";
rep2 = repeated[1] ? "✘ Repetition <b>found</b>." : "✔ <b>No</b> repetition.";
bitsyCode(".repetition_field_1_result").html(rep1);
bitsyCode(".repetition_field_2_result").html(rep2);
}
</script>
</body>
</html>
Preview:
Repetition: | |
Preview (Multiple Elements):
Repetition: | |
Repetition: | |
Share