简体   繁体   English

Typescript 中的字符串模式验证

[英]String Pattern Validation in Typescript

In Typescript, how to validate string pattern?在 Typescript 中,如何验证字符串模式? example const str = "ABC1-AB9"例如 const str = "ABC1-AB9"

  1. max length should be 8最大长度应为 8
  2. string pattern should be xxxx-xxx字符串模式应该是 xxxx-xxx
  3. x can be AZ and 0-9 only x 只能是 AZ 和 0-9
^[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.您可以通过访问https://regexr.com/网站并制作自己的自定义正则表达式来进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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