Currently, I am in the process of creating a credit card form that requires validation using checkValidity to match the specific card pattern that is dynamically added to the input field.
For example, if a user enters a Mastercard number such as 5454545454545454
, it will be formatted with spaces like this: 5454 5454 5454 5454
. Subsequently, I change the pattern attribute for that field to the Mastercard regex - ^(?:5[1-5][0-9]{14})$
. However, when triggering checkValidity on input blur, it returns false when it shouldn't. I suspect this issue stems from the formatting causing the pattern to fail.
My dilemma lies in finding a solution to validate patterns with spaces for the given regex, perhaps by removing spaces during validation or adjusting the regex to include spaces. Alternatively, I am open to exploring other solutions to address this challenge effectively.