Tuesday, May 23, 2017

Validate Stripe expiry date

I am using Stripe for payment processing. I want to validate the card date whether it is expired or not. The date format should be 1-12 months/upcoming years.

For example: 11/19, 12/18, 08/21, 01/20

Controller:

$exp = explode( '/', Input::get( 'card_expiry' ) );
if ( ( $exp[0] <= 12 ) && $exp[0] > 0 && ( is_int( $exp[1] ) ) ) {

} else {
    return back()->withErrors( 'Add a valid card expiry date' );
}

Form:

<div class="form-group">
    <label>Expiry</label>
    
    @if($errors->first('card_expiry'))
    <div class="text-danger"></div>
    @endif
</div>

I tried the above code but its not working.



via Asif Nawaz

Advertisement