pTutorial

New way to learn Programming

JQuery minimum length validation

JQuery length validation Example

Simple JQuery HTML form field validation to restrict user to put minimum number of letter.

HTML

<!DOCTYPE html>
<html>
<head>
<script src="http://freeonlinecompiler.ptutorial.com
/js/jquery.min.js"></script>
</head>
<body>
<h4>Minimum Length Validation</h4>
<table id="tab">
<tr>
</tr>
<tr>
<td>Enter Name *</td>
<td> <input type="text" id="uk" name="kk1"></td>
</tr>
<tr>
<td> <input type="submit" id="kk" value="Check"></td>
</tr>
</table>

<div id="divData"></div>
</body>
</html>


CSS

<style>
table{
border: 1px solid #080808;
margin: 5px;
padding: 10px;
}

</style>

JQuery length validation Example

<script>
$(document).ready(function (e) {
$('#kk').click(function () {
var z = $.trim($('#uk').val());
var k=z.length;
if(k==""){
$("#divData").html("Please Enter something First");
$("#uk").css("border-color","red")
return false;

}
else if((k>=4)){
$("#divData").html(z);
$("#uk").css("border-color","green")
return false;
}else{
$("#divData").html("Enter Atleast Four Character");
$("#uk").css("border-color","red")
return false;
}
})
});
</script>

Download

See Also


QUOTES OF THE DAY

The ballot is stronger than bullet.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER