Home  >  Article  >  Web Front-end  >  How does JS regular expression ensure that the input is an integer

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

零到壹度
零到壹度Original
2018-03-28 17:18:022223browse

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!

Statement:
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