Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下要验证的内容,如何创建一个正则表达式来检查这个?
我要验证
1-ABCD
这样我有一个数字,后跟一个连字符,然后是 4 个字母(不区分大小写)
谢谢!
您可以使用以下语句
"1-ABCD".match(/\d-\w{4}/);
希望能帮助到你。
Try this,
"1-ABCD".match(/^\d\-\w{4}$/)
Same as above one, additionally we need to add the start and end of string