1. Using <input type="number">
<label for="salary">Enter your salary:</label>
<input type="number" id="salary" name="salary">
2. Using pattern attribute
<label for="salary">Enter your salary:</label>
<input type="text" id="salary" name="salary" pattern="[0-9]+">
3. Using oninput event
<label for="salary">Enter your salary:</label>
<input type="text" id="salary" name="salary"
oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" />
No comments:
Post a Comment