top of page

Formatting text in Typescript

  • Writer: Neil Burchfield
    Neil Burchfield
  • Dec 1, 2019
  • 1 min read

Here are some common functions I've used for formatting text in Typescript.


Phone Numbers


Format a string to phone number (ex. 777-787-7979)


Validating a phone number (either formatted or unformatted)


URL


Validate whether a url is valid or not


Email


Validate whether a email address is valid or not


Credit Card


Format a credit card number (ex. 4111 1111 1111 1111)


Deconstruct the formatted credit card (ex. 4111111111111111)


Validate a credit card number (either formatted or unformatted)


Credit Card Expiration Date


Format a credit card expiration (ex. 10/22)


Deconstruct a formatted credit card expiration date (ex. {expMonth: 10, expYear: 22})


Validate a credit card expiration date (either formatted or unformatted)


 
 
 

Comments


Follow me

  • linkedin-logo
  • 68747470733a2f2f7777772e69636f6e66696e64
  • Twitter Clean

© 2022 Neil Burchfield

bottom of page