xxx-xxx-xxxx or (xxx)xxx-xxxx I can create regex for the first one with XXXX-XXXX-XXXX-4567 NOTE that the 4567 digits shown above relate to the last four digits of the card number. This question helps format the string to something like 1234-5678-9123-4567 But it does not help with the format required above. While looking for answers I also came across the following solution: I want to format a UITextField for entering a credit card number into such that it only allows digits to be entered and automatically inserts spaces so that the number is formatted like so: XXXX X...

Understanding the Context

ios - Formatting a UITextField for credit card input like (xxxx xxxx ... Most developers have seen UUIDs (Universally unique identifier), but what is the reason the UUID is split into chunks like XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX? The UUID is just a 128-bit number, and string1 = xxx-xx-xxxx or string1 = xx-xxxxxxx How can I make the regex accept both kinds of values for the same element? The x's represent numbers only.

Key Insights

so total number of digits = 9 (anything between 0-9) total number of elements in the value is either 11 or 10... depending on which format. and total number of dashes is either 2 or 1. Learn how to format phone numbers in the 'xxx-xxx-xxxx' style using a number input field. javascript - How to input phone no in this 'xxx-xxx-xxxx' format in ...

Final Thoughts