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

243
Views
¿Cómo verificar la fecha de vencimiento de la tarjeta de crédito?

El usuario completa la información de la tarjeta de crédito. Quiero que la validación funcione si el usuario ingresa la fecha de vencimiento antes de hoy. Pero la entrada es la siguiente; mm/aa. Sin embargo, el usuario ingresa los últimos 2 dígitos del año. Por ejemplo, supongamos que el usuario ingresa la fecha de vencimiento como 21/06. La fecha de hoy es 22/06. En este caso, la validación debería funcionar. Necesito verificar el mes y el año que ingresó el usuario. Quiero mostrar un mensaje de error si el usuario ingresa una fecha incorrecta. He estado buscando pero no puedo integrarlo.

¿Como puedó resolver esté problema?

 const [errorList, setErrorList] = useState({ expDateValidationStateError: true, }); const [expDateValidationState, setExpDateValidationState] = useState({ error: false, helperText: '', }); const expDateOnChange = (event) => { if (expDateValidator(event.target.value)) { setExpDateValidationState({ error: false, helperText: '' }); setErrorList({ ...errorList, expDateValidationStateError: false }); } else { setExpDateValidationState({ error: true, helperText: t('payment-credit-card.error-messages.exp_date') }); setErrorList({ ...errorList, expDateValidationStateError: true }); } };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Aquí está el código:

 const ccExpired = (date)=>{ const dateArr = date.split('/'); const exYear = +dateArr[1] + 2000; const exMonth = +dateArr[0] - 1; // JS months start with 0 const exDay = new Date(exYear,exMonth + 1,0).getDate(); const dateObj = new Date(exYear,exMonth,exDay - 2); // Timezones fix. const dateNow = new Date(); return dateNow > dateObj; } console.log("2/22 " + ccExpired('2/22')); console.log("3/33 " + ccExpired('3/33')); //This is for SO debug only, ignore. const currentMonth = (new Date().getMonth() + 1); const currentYear = (new Date().getFullYear()).toString().replace(/^20/, ''); const thisMonth = `${currentMonth}/${currentYear}`; const lastMonth = `${(currentMonth-1)}/${currentYear}`; const nextMonth = `${(currentMonth+1)}/${currentYear}`; console.log(thisMonth + " " + ccExpired(thisMonth)); console.log(lastMonth + " " + ccExpired(lastMonth)); console.log(nextMonth + " " + ccExpired(nextMonth));

about 4 years ago · Juan Pablo Isaza Report

0

O quizás

 const isCCExpired = str => { const [mm,yy] = str.split("/"); const dateObj = new Date(+yy + 2000,mm-1,15); // months are 0 based and don't take the 1st due to timezones console.log(dateObj); return dateObj.getTime() < new Date().getTime(); }; console.log("3/22",isCCExpired('3/22')); console.log("3/23",isCCExpired('3/23'));

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!