2

There is one field in table which is float and i have to insert only the float value in that but on submit i used the function for inserting the data into table and i want this numeric validation is happened on client side using jquery

Can anyone suggest me the clue??

2 Answers 2

2

Try this code and make it some modifications according your proper requirement

<script type="text/javascript">
$(document).ready(function () {
$('input[numeric]').keyup(function () {
var d = $(this).attr('numeric');
var val = $(this).val();
var orignalValue = val;
val = val.replace(/[0-9]*/g, "");
var msg = "Only Integer Values allowed.";
if (val != '') {
orignalValue = orignalValue.replace(/([^0-9].*)/g, "")
$(this).val(orignalValue);
alert(msg);
}
});
});
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

jQuery has an isnumeric() function already, so you could use that to do the check! Here's an example of how to use it as part of your client side validation:

if(!$.isNumeric($('#elementId').val())) {
    // show an error
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.