React Native MantineInputs

MaskInput

Format user input according to a mask pattern

Import: import { MaskInput } from 'react-native-mantine';

Usage

import { MaskInput } from 'react-native-mantine';

// Tokens: # digit, a letter, * alphanumeric
<MaskInput
  label="Phone"
  mask="+1 (###) ###-####"
  value={phone}
  onChangeText={setPhone}
  onChangeRaw={(raw, masked) => console.log(raw)}
  onComplete={(masked, raw) => console.log('done', raw)}
/>

// Mask skeleton as placeholder, clear incomplete value on blur
<MaskInput mask="##/##/####" showMask slotChar="_" autoClear />

Props

PropTypeDefaultDescription
mask (required)string | Array<string | RegExp>Mask pattern, e.g. "+1 (###) ###-####". Tokens: # digit, a letter, * alphanumeric
tokensMaskInputTokensCustom token definitions, merged with defaults (# digit, a letter, * alphanumeric)
slotCharstring"_"Character used to render empty mask slots in the placeholder
showMaskbooleanfalseDisplays the mask skeleton as placeholder when the input is empty
autoClearbooleanfalseClears the value on blur if the mask is not completely filled
valuestringMasked value for controlled component
defaultValuestringDefault value for uncontrolled component
onChangeText(masked: string) => voidCalled with the masked value
onChangeRaw(raw: string, masked: string) => voidCalled with the raw (unmasked) and masked values
onComplete(masked: string, raw: string) => voidCalled when the mask is completely filled
labelReact.ReactNodeInput label, inherited from TextInput
errorReact.ReactNodeError message, inherited from TextInput
applyMask(input, mask, tokens?) => { masked, raw, complete }Exported helper that applies a mask to an arbitrary string
getMaskPlaceholder(mask, slotChar?, tokens?) => stringExported helper that builds the mask skeleton placeholder

Source on GitHub · npm