代表js中所有数字的变量

variable that represents all the numbers in js

我需要一个代表任何数字的变量,我正在构建一个聊天机器人,对话的框架是对以数字方式表示的文档的请求,为此我需要这个变量,它可以检测到这是一个数字

if(message.body.includes(numberDocument)) {
    client.sendMessage(message.from, 'is the number of document: '+message.body);
}

numberDocument 代表我的可变数字,但它不起作用

var numberDocument = Number

您可以使用正则表达式检查邮件中是否包含数字。

您可以使用正则表达式 https://regexr.com/ 进行测试

if(message.body.match(/\d/g) {
        client.sendMessage(message.from, 'is the number of document: '+message.body);
}

也就是说如果消息中有数字...,您还可以尝试检查消息是否包含除数字以外的任何内容return错误

if(message.body.match(/\D/g) {
        client.sendMessage('invalid number');
}