
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-masked-text
Advanced tools
Text and TextInput with mask for React applications, based on benhurott/react-native-masked-text.
This is a simple masked text (normal text and input text) component for React.
Thanks to vanilla-masker =). Thanks to benhurott
React: 16.0.0 or higher
npm install react-masked-text --save
import React from 'react';
// import the component and the mask
import { TextInputMask, datetimeMask } from 'react-masked-text';
export const MyComponent = () => {
const myDateTextRef = React.createRef();
return (
<TextInputMask
ref={myDateTextRef}
mask={datetimeMask()}
/>
);
}
If you set this prop, this component becomes a controlled component.
Use this props if you're using this component as an uncontrolled component and you want to set its default value (initial value). You may notice that it doesn't make sense to set value and defaultValue at the same time.
creditCardMask: use the mask 9999 9999 9999 9999 and text keyboard.
cpfMask: use the mask 999.999.999-99 and text keyboard.
cnpjMask: use the mask 99.999.999/9999-99 and text keyboard.
zipCodeMask: use the mask 99999-999 and text keyboard.
onlyNumbersMask: accept only numbers on field with numeric keyboard.
moneyMask: use the mask R$ 0,00 on the field with text keyboard.
celPhoneMask: use the mask (99) 9999-9999 or (99) 99999-9999 (changing automaticaly by length).
datetimeMask: use datetime mask with a similiar moment format (default DD/MM/YYYY HH:mm:ss).
customMask: use your custom mask (see later in this doc).
Use customMask to basic mask formatting, use letter 'A' to letters and number '9' to numbers and separators like a space, /, -, etc... for example:
return (
<TextInputMask
ref={myDateTextRef}
mask={customMask('AAA-999/99')}
/>
);
getElement(): return the instance of TextInput component.isValid(): if the value inputed is valid for the mask.
getRawValue(): get the converted value of mask.
1234 1234 1234 1234 returns [1234, 1234, 1234, 1234].R$ 1.234,56 returns 1234.56.If you want, we expose the BaseMask. You can use it to create your own mask:
Ex:
import { BaseMask } from 'react-masked-text';
interface DollarMoneyMaskSettings {
precision: number;
separator: string;
delimiter: string;
unit: string;
suffixUnit: string;
zeroCents: boolean;
}
const DOLLAR_MONEY_MASK_SETTINGS: DollarMoneyMaskSettings = {
precision: 2,
separator: '.',
delimiter: ',',
unit: 'U$',
suffixUnit: '',
zeroCents: false,
};
class DollarMoneyMask extends BaseMask {
static getType(): string {
return 'dollar-money';
}
getValue(value: string, settings?: Partial<MoneyMaskSettings>, oldValue?: string): string {
const mergedSettings = super.mergeSettings(DOLLAR_MONEY_MASK_SETTINGS, settings) as MoneyMaskSettings;
if (mergedSettings.suffixUnit && oldValue && value) {
if (value.length === oldValue.length - 1) {
const cleared = this.removeNotNumbers(value);
value = cleared.substring(0, cleared.length - 1);
}
}
const masked = this.getVMasker().toMoney(value, mergedSettings);
return masked;
}
getRawValue(maskedValue: string, settings?: Partial<MoneyMaskSettings>): number {
const mergedSettings = super.mergeSettings(DOLLAR_MONEY_MASK_SETTINGS, settings) as MoneyMaskSettings;
let normalized = super.removeNotNumbers(maskedValue);
const dotPosition = normalized.length - mergedSettings.precision;
normalized = this._insert(normalized, dotPosition, '.');
return Number(normalized);
}
validate(): boolean {
return true;
}
private _insert(text: string, index: number, stringToInsert: string): string {
if (index > 0) {
return text.substring(0, index) + stringToInsert + text.substring(index, text.length);
} else {
return stringToInsert + text;
}
}
}
export const dollarMoneyMask = () => new DollarMoneyMask();
// dollar-money -> U$ 9,475.28
FAQs
Text and TextInput with mask for React applications, based on benhurott/react-native-masked-text.
The npm package react-masked-text receives a total of 534 weekly downloads. As such, react-masked-text popularity was classified as not popular.
We found that react-masked-text demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.