简体   繁体   中英

String Pattern Validation in Typescript

In Typescript, how to validate string pattern? example const str = "ABC1-AB9"

  1. max length should be 8
  2. string pattern should be xxxx-xxx
  3. x can be AZ and 0-9 only
^[A-z0-9]{4}-[A-z0-9]{3} [0-9]{1}

This could be the regex you are looking for. You can test the same by going to https://regexr.com/ website and making your own custom regex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM