日期:2014-05-17  浏览次数:20450 次

求[-1,1]的正则表达式
如题,限制-1 到 1之间的浮点数输入(包括-1 和 1),精度为6位小数,知道的朋友帮帮忙。谢谢~

------解决方案--------------------
C# code
    protected void Button1_Click(object sender, EventArgs e)
    {
        string str=TextBox1.Text; 

        string pattern = @"(?is)^(-?0+|0+)(\.\d{1,6})$";
        Regex reg = new Regex(pattern);
        bool isValid = reg.IsMatch(str);
    }

------解决方案--------------------
Regex.IsMatch(s,@"^((-?1)|(-?0\.\d{1,6})|0)$")