0

jquery data input validation min and max in number

<td align='right'>
  <label for="decimal"> <?php echo form_error('price') ?></label>
    <input style="background-color:#FFFF42" type="text" class="form-control" name="price" id="price" placeholder="price" value="<?php echo $price; ?>" />
</td>
<script type="text/javascript">

$('#price').keyup(function(){
  if ($(this).val() > 20 ){
     alert("Price Max USD. 20");
     $(this).val('20');
   }
   else if {
    ($(this).val() < 5 ){
    alert("Price Min USD. 5");
    $(this).val('5');
}
});
</script>

but this doesn't work there is no action

0

1 Answer 1

1

$(document).ready(function(){
  $('#price').keyup(function(){
    if ($(this).val() > 20 ){
         alert("Price Max USD. 20");
         $(this).val('20');
     }
     else if($(this).val() < 5 ){
        alert("Price Min USD. 5");
        $(this).val('5');
     }
  });
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<td align='right'>
  <label for="decimal"> <?php echo form_error('price') ?></label>
    <input style="background-color:#FFFF42" type="text" class="form-control" name="price" id="price" placeholder="price" value="" />
</td>

Sign up to request clarification or add additional context in comments.

3 Comments

how to hidden NaN in form validation?
NaN? what's that? form validation only validate input controls.
change NaN to 0, if(isNaN(tal)) var tal = 0;

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.