Semantic-Org/Semantic-UI · warning
{name} must be set to a number
Error message
{name} must be set to a number What it means
Default prompt for the Semantic UI Form `number` rule (settings.rules.number, form.js:1417). It tests against `settings.regExp.number` = `/^-?\d*(\.\d+)?$/` (form.js:1244). Quirk: the regex matches an empty string `''` and a lone `-`, so those pass validation — pair with an `empty` rule when the field is required.
Source
Thrown at src/definitions/behaviors/form.js:1261
integer : /^\-?\d+$/,
number : /^\-?\d*(\.\d+)?$/,
url : /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/i
},
text: {
unspecifiedRule : 'Please enter a valid value',
unspecifiedField : 'This field'
},
prompt: {
empty : '{name} must have a value',
checked : '{name} must be checked',
email : '{name} must be a valid e-mail',
url : '{name} must be a valid url',
regExp : '{name} is not formatted correctly',
integer : '{name} must be an integer',
decimal : '{name} must be a decimal number',
number : '{name} must be set to a number',
is : '{name} must be "{ruleValue}"',
isExactly : '{name} must be exactly "{ruleValue}"',
not : '{name} cannot be set to "{ruleValue}"',
notExactly : '{name} cannot be set to exactly "{ruleValue}"',
contain : '{name} must contain "{ruleValue}"',
containExactly : '{name} must contain exactly "{ruleValue}"',
doesntContain : '{name} cannot contain "{ruleValue}"',
doesntContainExactly : '{name} cannot contain exactly "{ruleValue}"',
minLength : '{name} must be at least {ruleValue} characters',
length : '{name} must be at least {ruleValue} characters',
exactLength : '{name} must be exactly {ruleValue} characters',
maxLength : '{name} cannot be longer than {ruleValue} characters',
match : '{name} must match {ruleValue} field',
different : '{name} must have a different value than {ruleValue} field',
creditCard : '{name} must be a valid credit card number',
minCount : '{name} must have at least {ruleValue} choices',
exactCount : '{name} must have exactly {ruleValue} choices',
maxCount : '{name} must have {ruleValue} or less choices'View on GitHub (pinned to 597843ab84)
Solutions
- Add `empty` as a separate rule if the field is required: `rules:[{type:'empty'},{type:'number'}]`.
- Strip grouping separators / replace comma decimals before validation.
- Use `integer` or `decimal` when a more specific numeric type is intended.
- Provide a custom `prompt`.
Example fix
// before - blank input passes the number regex
rules: [{ type: 'number' }]
// after - require presence + numeric
rules: [
{ type: 'empty', prompt: 'Amount is required' },
{ type: 'number', prompt: 'Amount must be a number' }
] Defensive patterns
Strategy: validation
Validate before calling
const v = $field.val();
const isNumber = /^-?\d*(\.\d+)?$/.test(v);
const isRequiredAndBlank = (v === '' || v === '-'); // these PASS the built-in rule!
if (!isNumber || isRequiredAndBlank) { /* warn */ } Type guard
const isStrictNumber = (v) => v !== '' && v !== '-' && /^-?\d*(\.\d+)?$/.test(String(v));
Prevention
- Always pair number with an empty rule when the field is required.
- Strip thousands separators before validating.
- Use integer/decimal for stricter contracts.
When it happens
Trigger: `{type:'number'}` with input `1.2.3`, `abc`, `--4`, or `3,14` (comma). Empty input or `-` alone do NOT trigger it (they pass).
Common situations: Required numeric fields left blank still passing because the regex matches `''`; localized comma decimals; multiple dots in pasted data.
Related errors
- {name} must be a decimal number
- {name} must be a valid url
- {name} is not formatted correctly
- {name} must be an integer
- {name} must be "{ruleValue}"
AI-assisted analysis of Semantic-Org/Semantic-UI@597843ab84 (2026-08-13).
Data as JSON: /api/errors/fd044d7593efaa95.
Report an issue: GitHub.