检查数字或文本字符串的输入框

Mat*_*att -1 javascript regex jquery input

我正在实现逻辑以使用url作为查询参数,具体取决于用户是否输入一系列数字或字母.如果用户输入数字,urlLocation则应使用第一个,否则应使用第二个.试图为第一个使用正则表达式,但我不确定如何正确实现该正则表达式.

<input id="imageid" type="text" />

if ($("#imageid").val() == '/[^0-9\.]/') {
    var urlLocation = "http://www.url.com/rest/v1/cms/story/id/" + imageid.value + "/orientation/" + orientation;
} else {
    var urlLocation = "http://www.url.com/rest/v1/cms/story/guid/" + imageid.value + "/orientation/" + orientation;
}
Run Code Online (Sandbox Code Playgroud)

JSFIDDLE示例:链接

tym*_*eJV 5

只是isNaN用来检查一个数字:

var val = $("#imageid").val();
if (isNaN(val)) {
    //Not a number!
} else {
    //Number!
}
Run Code Online (Sandbox Code Playgroud)