Skip to content

What masks return ​

What the mask functions return and what ends up in the field, in v-model and in your data. Every example is real tinyval-mask output.

In short ​

FunctionReturnsExample for phone()
mask(value, m)A string for the field'+7 (999) 123-45-67'
unmask(value, m)A string for data and the database'79991234567'
isComplete(value, m)true if all required positions are filledtrue
isValid(value, m)true if filled and correct (the date exists, the checksum matches)true
m.process(value)Everything at once — a MaskResult object, see below
attach → onChange{ value, raw, complete } on every field change
v-mask + v-modelThe model holds the string with the mask'+7 (999) 123-45-67'
v-mask.raw + v-modelThe model holds the unmasked value, like unmask'79991234567'

All functions return strings: even the number mask returns '1234.5', not 1234.5 — so leading zeros and precision aren't lost. Get a number with Number(...) or coerce.number.

What unmask returns ​

The unmasked value depends on the mask — it's what's convenient to store:

MaskIn the fieldunmask
Custom pattern '99-99'12-34'1234' — typed characters without literals
phone()+7 (999) 123-45-67'79991234567' — all digits including the country code
card()4276 1234 5678 9012'4276123456789012'
numberMask(), money()1 234,5 ₽'1234.5' — JavaScript format: a dot, no spaces
numberMask({ negative: true })-42'-42'
carPlate()А 123 ВС 77'А123ВС77' — Cyrillic, even if typed in Latin
kpp(), mac()7743AB001'7743AB001' — upper case

If the mask isn't fully filled, unmask returns what was typed so far: unmask('8999123', phone()) → '7999123'. Check completeness with isComplete.

MaskResult — everything at once ​

mask.process(value) returns the full result. You need it when writing your own field binding or component:

ts
phone().process('8999123');
json
{
  "value": "+7 (999) 123",
  "raw": "999123",
  "complete": false,
  "valid": false,
  "slots": [4, 5, 6, 9, 10, 11],
  "overflow": false
}
FieldDescription
valueThe formatted value — the same as mask returns
rawTyped characters in pattern positions, without literals. For a phone it has no country code: +7 is part of the pattern. So use unmask, not raw, for data
completeAll required positions are filled — the same as isComplete
validFilled and correct — the same as isValid
slotsIndexes of typed characters in value — the caret is placed by them
overflowThe input had characters that didn't fit: process('1234567') for '99-99' → true

Why raw and unmask differ: raw is the mask's internal value (the caret is computed from it), while unmask is the value for data, and each mask decides what it should be. For custom patterns they are the same.

In the field, in v-model and in data ​

With v-mask or attach:

WhereValue
In the <input>+7 (999) 123-45-67
In v-model'+7 (999) 123-45-67' — the same as in the field; with v-mask.raw — '79991234567'
In attach's onChange{ value: '+7 (999) 123-45-67', raw: '79991234567', complete: true, valid: true } — here raw is already the unmask result
In data for the server'79991234567' — after unmask in the schema, see Masks & validation

The model keeps the masked value on purpose: the field and the model always match, and the "clean" value is produced in one place — in the schema before sending.

See also ​