我需要一个表示任何数字的变量,我正在构建一个聊天机器人,对话的框架是对以数字方式表示的文档的请求,为此,我需要这个变量,它可以检测到它是一个数字
if(message.body.includes(numberDocument)) {
client.sendMessage(message.from, 'is the number of document: '+message.body);
}numberDocument表示我的变量数字,但它不起作用
var numberDocument = Number发布于 2020-08-22 01:00:19
您可以尝试使用正则表达式https://regexr.com/进行测试
if(message.body.match(/\d/g) {
client.sendMessage(message.from, 'is the number of document: '+message.body);
}也就是说,如果消息中有一个数字...,您还可以尝试检查该消息是否包含除数字以外的任何内容,并返回错误
if(message.body.match(/\D/g) {
client.sendMessage('invalid number');
}发布于 2020-08-22 00:49:35
您可以使用正则表达式来检查消息中是否包含数字。
https://stackoverflow.com/questions/63526927
复制相似问题