Need to trim space in the regular expression

Hi,
Am using regular expression validator , for to accept only numbers .  that validator function is
((0)+(\.[1-9](\d)?))|((0)+(\.(\d)[1-9]+))|(([1-9]+(0)?)+(\.\d+)?)|(([1-9]+(0)?)+(\.\d+)?)
1. Accept only numbers and also in decimal
2.It doesnot accept zero i.e greater than 0 only can accept,

Problem:
Eg:i.123(if space given ) Error message of validator is popping out .  
     ii,(space)12(space)3 Error message of validator is popping out .  

I need a expression , which should trim empty spaces also.
LVL 18
Rajar AhmedConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aherpsCommented:
You could just do a string replace on the input string:


inputString = inputString.Replace(" ","");

Open in new window

0
Rajar AhmedConsultantAuthor Commented:
hi, where should be added this code..
in aspx r source code..???
<tr>
                <td style="width: 100px">
                    Enter Price<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
                        ControlToValidate="txtfprice" ErrorMessage="*" Style="position: relative; left: 1px; top: 0px;"></asp:RequiredFieldValidator></td>
                <td style="width: 100px">
                    <asp:TextBox ID="txtfprice" runat="server" Style="position: relative"></asp:TextBox></td>
                <td style="width: 100px">
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtfprice"
                        ErrorMessage="Enter in Number only" Style="position: relative" ValidationExpression="((0)+(\.[1-9](\d)?))|((0)+(\.(\d)[1-9]+))|(([1-9]+(0)?)+(\.\d+)?)|(([1-9]+(0)?)+(\.\d+)?[ \t]+$)"></asp:RegularExpressionValidator></td>
            </tr>

Open in new window

0
Rajar AhmedConsultantAuthor Commented:
my aspx code
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection con;
        string constr = ConfigurationManager.AppSettings["cons"];
        con = new SqlConnection(constr);
        con.Open();
        
        SqlParameter foodprice = new SqlParameter("@price", SqlDbType.Float, 4);
        foodprice.Value = txtfprice.Text;
        SqlParameter foodquantity = new SqlParameter("@quantity", SqlDbType.Int, 4);
        
        cmd1.Parameters.Add(foodprice);
 
        int comment = cmd1.ExecuteNonQuery();
        if (comment == 1)
        {
 
            Label1.Text = "Your Value is Added";
        }
        else
        {
 
            Label1.Text = "Already Exists";
        }
        con.Close();
       
    }

Open in new window

0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

aherpsCommented:
You could allow spaces in the Validation input, and just parse the string replace at:

foodprice.Value = txtfprice.Text.Replace(" ","");
0
Rajar AhmedConsultantAuthor Commented:
this is how i changed , but still am gettin the error message of regex validator of that control..
SqlParameter foodprice = new SqlParameter("@price", SqlDbType.Float, 4);
foodprice.Value = txtfprice.Text.Replace(" ", "");

Open in new window

0
aherpsCommented:
You would still need to allow the validator to accept '\s' to allow the above code to work...

0
Rajar AhmedConsultantAuthor Commented:

wel, how can i alllow .. . ?????


this is my req ex validator  code...Is there any modificationn required  ..????

Or in aspx  source  code....

If any ,  plz highlight the changes in code ...

My Expression
((0)+(\.[1-9](\d)?))|((0)+(\.(\d)[1-9]+))|(([1-9]+(0)?)+(\.\d+)?)|(([1-9]+(0)?)+(\.\d+)?)
 
 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtfprice"
                        ErrorMessage="Enter in Number only" Style="position: relative; left: -235px; top: 0px;" ValidationExpression="((0)+(\.[1-9](\d)?))|((0)+(\.(\d)[1-9]+))|(([1-9]+(0)?)+(\.\d+)?)|(([1-9]+(0)?)+(\.\d+)?[ \t]+$)" Height="16px" Width="1px">*</asp:RegularExpressionValidator></td>

Open in new window

0
aherpsCommented:
If you're just trying to match numbers above 0 - you could change it to:

^[\s]|[1-9]\d*?[0]|[\s]*$

It allows spaces also. - You can strip them out after in the replace function in .vb code as you have done
0
Rajar AhmedConsultantAuthor Commented:
this regex not even accepting numbers ..
but i want a regex which  can accept numbers,decimal and truncate  empty spaces

0
aherpsCommented:
Whoops - sorry mate:
Try this:
^([1-9]\d*|\s)*(\.?([0-9]|\s)*)$

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rajar AhmedConsultantAuthor Commented:
it works......

Thanks a lot  mate....
0
Rajar AhmedConsultantAuthor Commented:
good
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.