Options
Option | HTML attribute | Type | Description |
---|---|---|---|
message | data-fv-numeric-message | String | The error message |
thousandsSeparator v0.7.0+ | data-fv-numeric-thousandsseparator | String | The thousands separator. The popular values are
|
decimalSeparator v0.7.0+ | data-fv-numeric-decimalseparator | String | The decimal separator. The popular values are
|
When setting options via HTML attributes, remember to enable the validator by setting data-fv-numeric="true".
You don't need to do that when
i) using HTML 5 type="number" attribute,
ii) and the step attribute must be specified which its value is not an integer
You don't need to do that when
i) using HTML 5 type="number" attribute,
ii) and the step attribute must be specified which its value is not an integer
The message and other options can be updated on the fly via the updateMessage() and updateOption() methods
The thousandsSeparator
and decimalSeparator
options are useful if your country use particular separators for thousands and decimal parts. See the next supporting locales section for more details.
If you want the value to support more special formats, you should use the transformer option. The modifying the value before validating example is good starting point.
Supporting locales
The thousands and decimal separators might take different value in certain countries. The following table introduces some popular values that are defined by various countries.
You can click the sample number to test:
Country | Thousands separator | Decimal separator | Valid examples | Invalid examples |
---|---|---|---|---|
An empty string | A dot (. ) | |||
United States | A comma (, ) | A dot (. ) | ||
France | A blank space | A comma (, ) | ||
Italy | A dot (. ) | A comma (, ) |
The example also uses the updateOption() method to set values for thousandsSeparator
and decimalSeparator
options.
Since the thousands and decimal separators are various, the field should use type="text" attribute. Using type="number" for field will restrict the input to use default separators for a number (an empty string for thousands, and a dot for decimal parts)
Related validators
The following validators might be useful to you: