怎么能知道控件下标并进行判断?帮忙解决下!

来源:百度知道 编辑:UC知道 时间:2024/05/24 17:23:22
比如1.23我要进行判断串中是否有符号和字符,但能出现"."
我怎么能知道这串的下标
就是数字,可以是小数,可以是整数,但不能是其他的字符或标点

^(+-)?\d+\(.\d+)?$

function $get(message)
{

return document.getElementById(message);

}
function check()
{
var Price=$get("Price");
if(Price.value=="")
{

alert("价格不能为空!");
Price.focus();
return false;

}

var digits="0123456789.";
var temp;

for(var i=0;i<Price.value.length;i++)
{

temp=Price.value.substring(i,i+1);
if(digits.indexOf(temp)==-1)
{

alert('系统提示:\n 单价输入错误。正确格式XX.XX(X代表数字)!');
Price.focus();
return false;

}

}

}

用正则表达式,你没有写明确你要判断的详细信息,我也没法给你写正则.