JavaScript中的许可keygen
因此,我在这里看到了另一个解决方案,当时我遇到了一个问题。虽然问题并没有完全解决。
这是我在这里发现的代码。
function makeid(length) {
var result = "";
var characters = '0123456789';
for (var i = 0; i < length; i++) {
result += characters[Math.floor(Math.random() * characters.length)];
}
result = result.match(/\d{1,4}/g).join("-");
return result;
}
console.log(makeid(16));
这是我现在拥有的当前代码。
function makeid(length) {
var result = "";
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for (var i = 0; i < length; i++) {
result += characters[Math.floor(Math.random() * characters.length)];
}
result = result.match(/\d{1,4}/g).join("-");
return result;
}
console.log(makeid(16));
我不想要输出。我希望输出在字母和数字中都可以使用,我不确定为什么它不会同时做!
So I saw another solution on here with a problem I was having. Though the problem isn't completely solved for me.
This is the code that I found on here.
function makeid(length) {
var result = "";
var characters = '0123456789';
for (var i = 0; i < length; i++) {
result += characters[Math.floor(Math.random() * characters.length)];
}
result = result.match(/\d{1,4}/g).join("-");
return result;
}
console.log(makeid(16));
And this is the current code I have now.
function makeid(length) {
var result = "";
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for (var i = 0; i < length; i++) {
result += characters[Math.floor(Math.random() * characters.length)];
}
result = result.match(/\d{1,4}/g).join("-");
return result;
}
console.log(makeid(16));
The output is not want I want. I want the output to be in both Letters and Numbers and I'm not sure why it won't do both!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您的
match()
仅在寻找数字(\ d
),而不是任何字符(。
):您可以通过使用
%
操作员来摆脱慢匹配一起:It's because your
match()
is only looking for digits (\d
) and not any character (.
):And you can get rid of slow
match
all together, by using%
operator: