How to implement this check in html / php / js? What would be if you enter a number less than / equal to 5, gave an error as in the screenshot

enter image description here

  • four
    Some kind of incomprehensible salad. Have you ever defined in the client or server side need this check. And then, if these are some kind of HYIPs for entering or withdrawing money, I will not even help - Mr. Black
  • It is necessary that the result be as in the screenshot. No, not HYIP - Alexander

2 answers 2

count = document.getElementById('count'); err = document.getElementsByClassName('err')[0]; count.onkeydown = function(event) { // count.value = count.value.replace(/[^0-9]/gim, ''); // if(isNaN(count.value)) {count.value = current; count.selectionEnd = sel;} key = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 8, 37, 38, 39, 40, 16, 17]; if(key.indexOf(event.keyCode) == -1) {return false;} this.onkeyup = function() { if(parseInt(count.value) < 5) { err.innerHTML = 'Мин. сумма 5'; count.style = 'border-color: #FF7F66; color: #FF7F66;'; } else { err.innerHTML = ''; count.style = ''; } } } 
 #count { padding: 12px; border-radius: 3px; border: 1px solid #C0C4C8; outline: none; transition: border .3s ease; } .err { color: #FF7F66; font-size: 12px; font-family: Segoe UI; margin-left: 4px; } 
 <label><input id='count' type="text"><div class='err'></div></label> 

  • bad option, try typing a few numbers in the middle, or move the cursor with the arrow - Grundy
  • @Grundy, corrected, try now. The jamb still remained, although the restrictions for the keys do, but still better than it was - Mr. Black
  • the last fix was bad, "message": "Uncaught ReferenceError: current is not defined", - Grundy
  • @Grundy, in this and cant. If you start to enter not with numbers. This can be fixed, but I still don’t like it. Now I will try to think of something else - Mr. Black
  • Well, in general, this message is due to the fact that in the last edition you transferred the definition of current lower than it is used, just add var current and the error disappears - Grundy

 $(document).ready(function() { $("form").submit(function() { var $form = $(this), $reqField = $(".required", $form), $errorText = $(".error-text", $form); if ($reqField.val() <= 5) { $reqField.addClass("error"); $errorText.addClass("show"); } else { $reqField.removeClass("error"); $errorText.removeClass("show"); } return false; }); }); 
 body { font-family: Arial; } .error { border: 1px solid #f00 !important; color: red; } input[type="text"] { color: #777; padding: 10px 15px; border-radius: 4px; border: 1px solid #333; } .error-text { display: none; color: red; font-size: 14px; } .error-text.show { display: block; } 
 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head> <body> <form action="#" method="post"> <input type="text" class="required"> <input type="submit"> <div class="error-text">мин.сумма 5</div> </form> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> </body> </html> 

  • one
    Why load the jquery site if you can do without it, right? This is an extra load of ~ 100kb. In addition, you can immediately check without pressing the button to send . And I also enter letters and no errors - Mr. Black
  • Of course, it's better without jquery, I completely agree, I vote for your option. - Alexander

Protected by spirit community member Jun 5 '16 at 21:06 .

Thank you for your interest in this issue. Since he collected a large number of low-quality and spam responses, which had to be deleted, now it’s necessary to have 10 reputation points on the site (the bonus for account association is not counted ).

Maybe you want to answer one of the unanswered questions ?