#rizkieawan-react
1 messages · Page 1 of 1 (latest)
im new to stripe
and now i want to add validation to cardExp element
it will only accept card with exp date minimum +6 month from now
its not possible to do that unfortunately! There's no way to get notified of the exact value the customer is entering into the Element(there's an onChange event you can listen to for any validation errors like the date being in the past, but you can't really customise it to make it more restrictive like that
ohh i see
the only way to do this would be to check the details after the card is entered — i.e call createPaymentMethod when the customer is ready to pay, and then check the details of that PaymentMethod object (you can read the expiry from that) before proceeding
i tried to create custom input for the exp but how to put it when call createPaymentMethod?
type: "card",
card: elements.getElement("cardNumber")!,
billing_details: {
name: cardName,
},
});```
how to add exp value from input to that card params?
or it needs to pass an object instead of an element cardNumber
you can't(you can't supply the expiry yourself from your own inputs)
the only option is the one I said, you'd use our Elements, and check the details of the PaymentMethod after, you can't implement this validation on the input itself unfortunately, it's just not supported.
ohhh then it needs to be checked when createPaymentMethods deliver the response?
yes, paymentMethod.card.expiry_month I think can be accessed to check what the customer entered