Detected form widget input type number step validation guide

Make number fields behave after the Detected Form widget connects your form: how min, max, step and required interact, mobile keyboards, and a test pass.

James HollowayWeb Development Lead7 min read

Detected form widget input type number step validation problems usually show up as a visitor typing a perfectly reasonable quantity and the browser refusing to submit. The widget connects a form you already run; it does not rewrite your inputs. So the rules that decide whether a number is acceptable live in your own markup, and they are worth auditing once.

This guide maps how type="number", min, max, step and required interact in the browser, explains the step base rule that quietly rejects values, covers the mobile keyboard combinations, and ends with a repeatable test pass you can run before launch.

What the Detected Form widget does and does not change

The Detected Form widget connects an existing HTML form to WidgetJar. You configure widgets in the panel and install the WidgetJar embed script on your registered domain. The widget is not a form builder and not a custom calculator — your inputs, their name attributes, their labels and their constraint attributes stay in your markup and remain yours to fix.

That is good news for number fields. When a browser rejects a value, it is following instructions you wrote: the same attributes MDN lists as the built-in constraint set, where min, max and step constrain numeric values and the increment from the minimum, and required blocks an empty submit MDN client-side form validation. When a field is invalid, the browser marks it :invalid, blocks submission and shows its own message.

And because client-side checks are only an initial filter that anyone can bypass, keep an equivalent range check on whatever receives the submission MDN client-side form validation. The data your endpoint receives is a set of name/value pairs, so an out-of-range number can arrive if the request is crafted by hand MDN sending and retrieving form data.

Map the four constraint attributes before you touch the widget

Treat each attribute as a separate rule with a separate failure mode.

  • type="number" gives you a numeric control with spinner arrows. It is not a formatter: leading zeros, whitespace and pasted text behave differently than in a text field, and browsers vary in how they render decimals.
  • min and max are inclusive range checks. A value outside the range is invalid, but a value inside the range can still fail if the step pattern is broken.
  • step defines the increment the value must land on. This is the attribute that causes most "the validation is broken" reports.
  • required only refuses an empty value. A space or a stray character is still a value to the browser, which is why type and step matter so much.

Only mark fields required when you genuinely need the data. MDN notes that flagging required fields clearly is a WCAG expectation too, not just good manners MDN client-side form validation. If you want the marker wording to stay consistent after the widget connects, the existing guide to the required field asterisk explained covers labels and native validation behavior.

The step base rule that silently rejects valid values

The browser checks a numeric value against min + n × step. When min is present it becomes the base; when it is absent the base falls back to zero (or in some cases the value attribute). This is the single most common reason a value looks fine and is still rejected.

This pair works for whole-number quantities:

<label for="qty">Quantity (1 to 10) *</label>
<input type="number" id="qty" name="qty" min="1" max="10" step="1" required>

This pair silently rejects every even quantity, because the base is 1 and the allowed values become 1, 3, 5, 7 and 9:

<input type="number" id="qty" name="qty" min="1" max="10" step="2" required>

Two practical rules follow. For counts and quantities, use step="1" with a min that is a whole number. If you need a half-unit increment such as 2.5, set min to a value that itself lands on the step, for example min="0.5" step="0.5", and write the hint so visitors can predict it.

Decimals, currency and odd increments

Money and measurements with more than one decimal place are where type="number" starts to fight you. Browsers format decimals differently, spinner arrows feel wrong for a price, and a step of 0.01 on a large range invites rounding errors from real prices.

For those fields, type="text" with inputmode="decimal" plus an explicit hint is often the calmer choice: sighted mobile users still get a numeric keyboard, and you keep control of the wording. You lose the free range and step checks, so add a small scripted check and keep the server-side validation. If you want to customize the words the browser shows on the fields that do keep native constraints, the existing guide to native HTML form validation messages customizing walks through setCustomValidity without breaking native behavior.

Mobile keyboards: match `type` and `inputmode` to the value

The combination of type and inputmode decides which keyboard appears, and it varies by device and keyboard app. Test on a real phone rather than only in a desktop emulator.

  • type="number" raises a numeric keypad on both iOS and Android, but punctuation availability differs and some keyboards hide the decimal separator.
  • type="text" with inputmode="numeric" raises a digits-only keypad.
  • type="text" with inputmode="decimal" raises a keypad that includes a decimal separator where the platform supports it.

The failure to watch for is a field that accepts a decimal in your step pattern while the phone keyboard offers no way to type a decimal point. If your step allows fractions, confirm the visitor can actually enter one.

Write hints and error messages that explain the rule

Native browser messages are terse. Pair the field with a visible hint and link it with aria-describedby so screen readers announce it with the label:

<label for="qty">Quantity (1 to 10) *</label>
<input type="number" id="qty" name="qty" min="1" max="10" step="1" required
       aria-describedby="qty-hint">
<p id="qty-hint">Whole numbers only. Enter between 1 and 10.</p>

The hint states the range and the increment in plain language, which is exactly what a native step error fails to explain. For wording and inline placement patterns that work on small business forms, see the existing guide to contact form error messages.

If the number field sits inside a popup, the dialog must also be named and focused correctly, because W3C's dialog pattern requires an accessible name via aria-labelledby or aria-label and focus moving into the dialog on open W3C modal dialog pattern. Otherwise a validation message inside a modal can go unheard.

Keep the label and required state intact after the widget connects

Inspect the rendered page, not your source template, once the embed script runs. Confirm that:

  1. The <label for> value still matches the input id.
  2. The required asterisk is in the label text, not only in a CSS pseudo-element.
  3. required, min, max and step are still on the input element.
  4. aria-describedby points to an element that exists in the live DOM.

A repeatable browser test pass

Run this on Chrome, Safari, Firefox and one mobile browser, and repeat it after any markup change.

Step Action Expected result
1 Submit with the field empty Submission blocked, required message shown, focus on the field
2 Enter exact min, exact max, min plus one step, and max minus one step All accepted
3 Enter a value inside the range but off the step pattern Blocked, and the hint explains the increment
4 Paste non-numeric text and submit Blocked, not silently discarded
5 On a phone, type the largest value you support and any decimal Keypad allows every character the step needs
6 Tab through with VoiceOver or NVDA Label, required state and hint are announced

Finish by sending one crafted request outside the browser to confirm the endpoint rejects out-of-range values on its own.

Common failures, checked first

  • A step base mismatch. If min does not divide cleanly into the step, values inside the range still fail. Fix the base before hunting for a validation bug.
  • Duplicate name attributes. Two inputs sharing a name produce confusing payloads; the existing guide to name attribute missing submissions covers the audit.
  • A submit handler rejecting the value. A custom script can block submission regardless of native attributes. Watch the console and the form's listeners.
  • A hidden required field. If show/hide logic hides a required number input, the form can never submit; the existing guide to conditional logic show and hide fields explains safe required-state handling.

Connect your form with the constraints already right

The Detected Form widget puts your existing form in front of WidgetJar's capabilities without rewriting your inputs, so predictable number validation comes down to three things: a min that agrees with your step, a hint that names the range out loud, and a short browser test pass you actually run. Sort out the step base first; it resolves more apparent validation bugs than any other single change.

When the markup is ready, review the Detected Form widget setup and connect the form you already have.

  • detected form widget input type number step validation
  • forms
  • validation
  • accessibility
  • detected form

Written by

James Holloway

Web Development Lead at WidgetJar

Keep reading

Get started

Your next lead is one line away.

Pick a design, make it yours and paste a single script tag. Every widget type is included, and you do not need a credit card to start.

<script src="https://cdn.widgetjar.com/wj-assets/embed.js" defer></script>