Wednesday, June 13, 2018

Cách để chỉ cho nhập số trên input html

- Chỉ cho nhập số nguyên dương:
<input oninput="this.value = this.value.replace(/[^0-9]/g, '')">
<input name="num" 
                  type="number"
                  min="1"
                  step="1"
                  onkeypress="return event.charCode >= 48 && event.charCode <= 57"
                  title="Numbers only">
- Chỉ cho phép nhập số dương
<input type="text" oninput<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" >="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" >

No comments:

Post a Comment