Text box allows only positive integer greater than 0

The system has a field, set the parameters, the user can limit the input of a positive integer greater than 0:

 

<input type="text" name="non" ng-model="non" 
                    onpaste="return false;"
                    onkeyup="if (
                                    this.value.length == 1
                                ) {
                                    this.value = this.value.replace(/[^1-9]/g, '')
                                }
                                else {
                                    this.value = this.value.replace(/\D/g, '')
                                }"
                    onafterpaste="if (
                                    this.value.length == 1) {
                                    this.value = this.value.replace(/[^1-9]/g, '0')
                                }
                                else {
                                    this.value = this.value.replace(/\D/g, '')
                                }" />
Source Code

 

The above onpaste a property, that is to say, to paste text box does not accept data.

 

Guess you like

Origin www.cnblogs.com/insus/p/12504321.html