pTutorial

New way to learn Programming

JQuery checking for all numbers

JQuery : Form validation - checking for all numbers with method.

Often situations arise when web master wanted from the user to put only number like phone number, credit card number zip code or STD code. You can simply use pre define JQuery isNumeric function with the help example.

Checking for all number example JQuery

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/
libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function (e) {
$('#kk').click(function () {
var z = $.trim($('#uk').val());
if ($.isNumeric(z)) {
$('#kk').css("border-color", "green");
$('#divData').html("You have enter "+" " +z);
$('#uk').css("border-color", "green");
$('#tab').css("border-color", "green");
return false;
} else {
$('#kk').css("border-color", "red");
$('#uk').css("border-color", "red");
$('#divData').html("Please enter Numeric Only");
$('#tab').css("border-color", "red");
return false;

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

</style>
</head>
<body>
<h4>Only Numeric is allowed</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>

Download

Explanation

The isNumeric function is returned true if given input is numeric otherwise return false. See the above example to get understand the concept of isNumeric method.

See Also


QUOTES OF THE DAY

Tomorrow life is too late, live today.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER