Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
How can I create an input mask for MM/YY

I want to create a React Native input component for a credit card expiration date.

I believe I should input mask should be in the format for MM/YY. I'm not sure about autofill with autoCompleteType="cc-exp" and textContentType="creditCardNumber".

How can this be done without a library and only javascript/typescript?

InputCreditCardExpirationDate.tsx

  // React Hooks: State
  const [value, setValue] = useState<string>('');

  const formatMMY = (string: string): string => {
    // HOW?
  };

  // On Change
  const onChange = (text: string): void => {
    // MM/YY
    text = formatMMY(text);

    if (text.length >= 1) {
      // Set State
      setValue(text);

      // Props: On Change Text
      onChangeText(text);
    }
  };

  return (
    <Input
      value={value}
      placeholder={placeholder || 'Expires'}
      label={label ? label : 'Expires'}
      keyboardType="numeric"
      onChangeText={onChange}
      autoCompleteType="cc-exp" // Android Only
      textContentType="creditCardNumber" // iOS Only
      maxLength={7}
      darkMode={darkMode || false}
    />
  );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I solved this issue by using a library "react-native-masked-text"

import { TextInputMask } from 'react-native-masked-text'

...

 <TextInputMask
 placeholder="mm / yy"
 style={styles.inputLine} 
 placeholderTextColor="#4D4D4D" 
 refInput={ref =>{setExDateRef(ref)}}
 includeRawValueInChangeText={true}
 onChangeText={(maskedText) => { setCardExpiry(maskedText); }}
 value={cardExpiry} 
 type={'custom'}
 options={{mask: '99/99'}}
 keyboardType={'numeric'}
 onSubmitEditing={() => {cvvRef.focus() }}
 returnKeyType="next"
  />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!