728x90
1. oninput ์ด๋ฒคํธ, ์ ๊ท์, replace() ํจ์ ํ์ฉ
oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"
<th>์ฐ๋ฝ์ฒ</th>
<td>
<input type="text" id="info01" name="info04" value="" maxlength="3" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');">
<span class="date">-</span>
<input type="text" id="info02" name="info05" value="" maxlength="4" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');">
<span class="date">-</span>
<input type="text" id="info03" name="info06" value="" maxlength="4" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');">
</td>
</tr>
2. input type "number"
<input type="number">
<th>์ฐ๋ฝ์ฒ</th>
<td>
<input type="number" id="info01" name="info04" value="" maxlength="3">
<span class="date">-</span>
<input type="number" id="info02" name="info05" value="" maxlength="4">
<span class="date">-</span>
<input type="number" id="info03" name="info06" value="" maxlength="4">
</td>
</tr>
3. ์ ๋ ฅ๋ keycode ์ฒดํฌํ๊ธฐ
<input type="text" onkeypress="return checkNumber(event)">
function checkNumber(event) {
if(event.key === '.'
|| event.key === '-'
|| event.key >= 0 && event.key <= 9) {
return true;
}
return false;
}
์ถ์ฒ: https://hianna.tistory.com/413
'js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JavaScript] Location URL ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ (0) | 2022.01.18 |
---|---|
JSON ๊ฐ์ฒด์ parse / stringify ์ฐจ์ด (0) | 2022.01.10 |
[jQuery] <input type= 'file' ์ด๋ฏธ์ง ์ ํ ์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๊ตฌํ (1) | 2021.12.15 |
[JavaScript] Input elements should have autocomplete attributes (0) | 2021.12.01 |
[jQuery]๋์ append ํ .find() .remove() (0) | 2021.11.19 |