使用Javascript在文本框中仅允许数字值

问题描述:

我只允许在文本中输入数字值,如果用户输入字母字符,则应警告用户.对优化和简短的JavaScript代码有何建议?

I want to allow only numeric values to be entered into the text and if user enters alphabetic character it should warn the user. Any suggestion for optimized and short javascript code?

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

来自此处