在提示中检测到无效号码 [英] Detect invalid number in prompt
本文介绍了在提示中检测到无效号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在提示中输入电话号码
I want to get the number in a prompt
var pr = prompt("Tile size in pixels?", "150");
if(pr != null){
console.log(pr);
if (parseInt(pr) != NaN) {loadImage(parseInt(pr));}
else { alert("pick a valid number");}
}
但是,当我在提示符下键入一个单词时,会执行loadImage()
.
However when I type a word in the prompt the loadImage()
is executed.
我在控制台中签到并且pr
是相同的词,并且在我运行时:
I checked in console and pr
is the same word, and when I run:
parseInt("word")
在chrome控制台中,
的结果是NaN
.
in console of chrome the result is NaN
.
但是当我跑步时:
parseInt("word") == NaN
结果是false
如何检测提示中输入的无效号码?
How to detect invalid number input in prompt?
推荐答案
您可以使用isNaN()
isNaN(1) == false // true
isNaN("hi there") == true // true
isNaN("606") == false // true
// etc etc etc
这篇关于在提示中检测到无效号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文