Home > Web Front-end > JS Tutorial > body text

How does JS regular expression ensure that the input is an integer

零到壹度
Release: 2018-03-28 17:18:02
Original
2285 people have browsed it

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>
Copy after login
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);//返回输入框  
    });
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template