Input masks reduce the number of validation errors, which can reduce site abandonments.
According to Baymard, 64% of sites don’t use input masks (or don’t use them correctly) to help shoppers enter their data in restricted inputs. And in the testing they did, 89% didn’t follow formatting examples for restricted fields.
You should also consider regional differences in format. For example, the date format in the US is MM/DD/YY, in Europe it’s DD/MM/YY, and in Canada and Japan it’s YYYY/MM/DD.
For more information on the formatting of the credit card number specifically, please refer to best practice #119.