The leading plus sign is not allowed to enter a number in Chrome. Workaround?

I am writing a small javascript utility that does some numerical calculations. Almost all inputs are true numbers (that is, I do math with them, they are not zip codes or something like that). Some of these numbers are modifiers that must be added to other numbers before calculating. I would like these numbers to be displayed with a caption, with a pointer "in front" if the value is greater than zero. This works fine in Firefox and IE, which do nothing special with number entries. However, Chrome does not allow a plus sign in the input value number, although it parseFloatcan handle it just fine. Right now, my code manually adds the value +to the field value, which causes it to break in Chrome.

Is there a way to make this work in Chrome? Apparently ( generating CSS content before or after the input elements) :beforewill not help me here. Ideally, I would like to keep the type number; if all else fails, I can just use it text, but I rely on attributes min, maxand step.

UPDATE: adding novalidateto the field allows a plus sign, but then Chrome will declare valuean empty line. While checking the element, I see no way to get the displayed value if it is invalid, even with novalidate.

UPDATE: it seems that there is no good way to get the value from an invalid field ( How to get the original value <input type = "number" β†’ field? ). And the check confirms that the attributes min, maxand are stepnot allowed for input[type=text]. If I don’t come up with something else, I’ll probably just give up the plus signs.

+4
source share
2 answers

I tried a number with a plus sign. It seems to work in Chrome

<div ng-app>
<div ng-controller="PatternTestCtrl">
    <form name="ngform">
        <input type="number" name="numVal" ng-model="numValModel" ng-pattern="/[0-9]{5}/" maxlength="5" ng-maxlength="5"/>
    </form>
</div>
</div>
http://jsfiddle.net/jdev_hari/1c4te0cw/1/

My browser version is version 37.0.2062.124 m. Is this still a problem?

0
source

I had the same problem. I used a workaround with a pattern and type = "tel" to launch the numeric keypad on a mobile device

0

All Articles