简体   繁体   English

如何防止插入值大于用户在文本字段中输入的数字

[英]How to prevent inserting value greater than the number which user enters in text field

I had a text field called premium where the user can enter max of 10 digits.After they click submit another text field called deposit opens where it can enter a max of 7 digits..But I want to give a condition where the user cant enter the deposit more than premium.. Example: 我有一个名为premium的文本字段,用户可以输入最多10位数字。单击提交后,另一个名为deposit的文本字段可以输入最多7位数字。但是我想给用户一个不能输入的条件存款多于溢价。示例:

If premium=111 Deposit should be <=111

If the deposit is more than premium onchange the value should be changed back to premium ie, to 111 如果保证金大于更改时的溢价,则应将值改回溢价,即更改为111

Can someone help me in this I got stuck. 有人可以帮我解决这个问题。 Thanks. 谢谢。 Jsfiddle for above: https://jsfiddle.net/U3pVM/28556/ 上面的Jsfiddle: https ://jsfiddle.net/U3pVM/28556/

Kindly check once and upvote if you find it helpful 请检查一次并赞成,如果发现有帮助

https://jsfiddle.net/U3pVM/28558/ https://jsfiddle.net/U3pVM/28558/

             function TodoCtrl($scope) {

                $scope.hide=false;
                $scope.submit = function() {
                   $scope.hide=true;
                   if($scope.deposit && parseInt($scope.deposit)>parseInt($scope.premium)){

                     $scope.deposit = $scope.premium;
                  }
               };

             }

hi you can add tyr with following code as a attribute to deposit input field. 您好,您可以使用以下代码将tyr作为属性添加到存款输入字段。 And give id "preminum" to premium input field. 并将ID“ preminum”赋予高级输入字段。

onkeypress="return Number(this.value()+""+event.key) <= Number($('#premium').value());"

This won't allow user to enter value more than premium. 这将不允许用户输入超过溢价的值。

Add this code: 添加此代码:

$scope.$watch('deposit', function(newVal, oldVal){     
    if(newVal && newVal*1 > $scope.premium*1)
        $scope.deposit = $scope.premium;    
})

Html5 supports min and max with number inputs. HTML5支持带有数字输入的最小和最大。 For example: <input type="number" name="deposit" min="1" max="111"> Anyway it is good to check all user inputs on server side. 例如: <input type="number" name="deposit" min="1" max="111">无论如何,最好检查服务器端的所有用户输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何防止在html的数字字段中插入大于最大值的值 - How to prevent inserting value that is greater than to max in number field in html 阻止用户输入一个浮点数,该数字大于3位小数 - Prevent user from entering a float number, greater than 3 decimals 使用用户输入的文本字段值更新数组 - Update an array using a text field value that a user enters 当用户在输入字段中输入数据时,如何从把手页面获取 jquery 中的输入文本值? - How to get the input text value in jquery from handlebar page when user enters data in input field? 防止用户在输入字段中输入大于2位数字的值 - Prevent users from entering a value greater than 2 digits in an input field 当用户仍在javascript中将值输入字段时,如何验证字段条目? - how to validate a field entry as user still enters the value into a field in javascript? 当文本字段长度大于定义的数字时如何显示警报 - How to Show Alert When Text Field Length Greater than Defined Number 用户输入后如何获取输入字段的值 - How to get the value of input field as soon as user enters it 当用户在html表的文本字段中输入文本时,调用哪个事件侦听器 - which event listener to call when user enters the text in the text field in a html table 如果用户在文本字段中输入空格,则Javascript为ckeck - Javascript to ckeck if user enters space in the text field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM