When I click on the input <input type="number" id="n" />
; type some key on keypress
function of the input. Then typing .
though it display on the input but I cannot get see .
in $('#n').val()
.
For example after typing: 123.
Then $('#n').val()
only return 123
.
Is there any attribute of <input type="number" />
that I can get its raw value
which is 123.
rather than 123
?
$("#n").on("keypress", function(event) {
console.log($("#n").val());
});
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<input type="number" pattern="[0-9]{1,2}([\.][0-9]{1,2})?" id="n" step="0.01" />
UPDATE:
input
MUST have type number to allow it to showing number input only on softkeyboard on mobile web.It should check for pattern 99.99 and work as below:
- When type 9 OK // input: 9
- type 9 OK // input: 99
- type 9 NO, it not match pattern // input: 99
- Then type 1 NO, it not match pattern // input: 99
- ..Free type typing anything rather than dot(.) here...
- type dot(.) OK // input: 99.
- type 9 OK // input: 99.9
- type 9 OK // input: 99.99
- type 9 NO // input: 99.99
Without detect the existance dot(.) how can I detect the case of typing multiple .
consecutively ?