Javascript 查找输入中除浮点数以外的任何字符的正则表达式

Javascript regular expression to find any character other than floating point numbers in the input

用户可以提供任何类型的数据。我需要确保输入字符串只包含浮点数。因此,我需要确保数据仅包含数字或点 (.),如果输入数据包含数字或点以外的任何内容,则 return 为 false。有人可以帮我 javascript 正则表达式吗?我试着搜索了很多。但是我找不到针对我的具体案例的任何帮助。

So this should return characters for cases like
12.09a23
aa12.12
abcd

更新

我不想查看输入的字符串是否有浮点数。我想看看输入是否有除浮点数以外的任何东西。例如,如果输入有 12.3aa23,我想显示输入有 aa,所以这是无效输入。

function isDigit(str){
var n = str.search(/^(\d)*(\.)*(\d)*$/); 
return (n!==-1);
}

来自 here and here:-)

jsfiddle

您可以使用 /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/ 正则表达式在单个字符串中查找浮点数(因此,添加锚点)。 Source

此外,这里有一个demo

片段:

if ("12.09a23".search(/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/) != -1) {
  alert("Floating number detected! ")
}
else
{ 
  alert("Floating number not detected! Invalid data inside string: " + "12.09a23".replace(/[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/g, '')) 
}