1

Issue in Android browser (4.03) for below markup.

<html> 
<body> 
Androind 4.03 Browser test page<br />
Type .9 in the input field below and click/tap button below.<br />
Browser validation is clearing contents in input field.<br /></br/>


<input type="number" pattern="[0-9\.]*" step="0.1" min="0.0"></input> <br /><br /><br />

<input type="button" value="Validate" />

</body>
</html>

I expect number keypad on focus and it works fine with iphone and androind 2.x browsers. But when I enter decimal less than 1 like .9 or .1 it does validate onblur and clear input field.

I expect input to accept any numbers and decimals...

Run code sample here

1 Answer 1

1

Old post, but I've run into this as well.

What I've done to work around it is to catch '.' on keydown (keyup worked fine on android, but caused problems on IOS), and set the value to 0 before the . is applied. I noticed, however, that on the android browser at least, this interfered with the ability to completely erase the number after that (if you were to backspace), so I had to catch that too.

// within a keydown handler for the input, 
// where "this" is the input, and "e" is the event

// make it 0 before the . gets applied
if((e.keyCode == 190 || e.keyCode = 46)
    && (!this.value || this.value == '.'))
{
    this.value = 0;
    return;
}

// ...but that screws up the cursor position on
// some browsers, so handle the backspace 
if(e.keyCode == 8 && this.value == '0.')
{
    this.value = '';
    return;
}

Feels hacky, but seems to work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.