This article mainly shares with you a method of how to ensure that the input is an integer using JS regular expressions. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor and take a look.
<span class="show_total"> <span class="edit_ifo">{{totalRunTimes}}</span> <a class="btn btn-primary edit_btn" (click)="editTotalTimes()">编辑</a> </span>
editTotalTimes() { $('.show_total').addClass("display_none"); $('.edit_total').removeClass("display_none"); // 确保输入的为整数 $('.total_times').off('input propertychange'); 、('.total_times').on('input propertychange', function() { let v = $(this).val().toString();//获取输入框的数 v = v.replace(/\D/g,'');//将除整数的其他字符替换为空 $(this).val(v);//返回输入框 }); }
In this way, all entered non-digits will be replaced with empty strings.
Related recommendations:
#JS regular expression to determine whether the input is an integer
JS Regular expression to determine whether the input is an integer
The above is the detailed content of How does JS regular expression ensure that the input is an integer. For more information, please follow other related articles on the PHP Chinese website!