Avatar of cannase
cannase asked on

RegularExpressionValidator - Issue

My Asp.net page contains a RequiredFieldValidator and RegularExpressionValidator.  Texbox1 collects a bid amount for an item and is typically in us dollars.  This is the code I used ValidationExpression="^\d+(\.\d\d)?$" ControlToValidate="TextBox1".  

It works great.  My application is setup to email me when an error occurs on the site.  Below is an extract of a recent error.

The error description is as follows : System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown. ---> System.InvalidCastException: Cast from string "35.000 US$" to type 'Double' is not valid. ---> System.FormatException: Input string was not in a correct format.

Why can't I replicate this error.  When testing from IE 7. The form will not allow me to enter "35.000 US$" .   Does RequiredFieldValidator and RegularExpressionValidator only work on certain web clients?  Do I need to add addtional validation bin the code behind?

Thank you in advance for your help.
ASP.NET

Avatar of undefined
Last Comment
cannase

8/22/2022 - Mon
G0ggy

Dollar amount: \$[0-9]+(\.[0-9][0-9])?

It looks to me like you've taken the entry and in your code behind you're trying to assign it to a parameter set up as a double.
ASKER
cannase

This ValidationExpression should only allow a user to enter in a numberic money value into the texbox.  

It they add "$" or "US" the form should not submit.  In the example above a user entered "35.000 US$" and the form did submit and the application genrated an error.  I am wondering how reliable the asp.net validation tools are and are they dependant on certain browsers????
G0ggy

Take the dollar sign off mine.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
cannase

Thank you for your help.  I removed the \$ and it works.  

One more question on this please.  In some cases I have a requiredfieldvalidation and from time to time, I recieve an error saying that the form was submitted and the value was not supplied.  Example below

SP_Buy_New_Buyer_Insert_New_Buyer' expects parameter '@q1', which was not supplied.

How could this be when the text box has a requiredfieldvalidation?
G0ggy

I doubt whether it is your validators fault. Looks like you've specified a parameter in your stored procedure (@q1) but not supplied the parameter in your command, but without your code it is difficult to say.
ASKER
cannase

The code has been in production and working for 6 months.  I have tried to complete the form without textbox1 - (this is the value for @q1) and the form will not submit.  It does it's job and states a value this field is required.  Then I get emailed "SP_Buy_New_Buyer_Insert_New_Buyer' expects parameter '@q1', which was not supplied."  from time to time.  Strange.  Is it posssible that some browser are not compatible with these validators?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
G0ggy

Can you post your code please?
ASKER
cannase

<TD width="450"><asp:textbox id="TextBox1" runat="server" Width="240px"></asp:textbox>*&nbsp;&nbsp;<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" CssClass="BuyerFormValText" ControlToValidate="TextBox1"></asp:requiredfieldvalidator></TD>

is the code in the aspx page.  I will post the coded bihind in a moment.  Thank you
ASKER
cannase

Sub NewBuyerSetup()
        MyConnection = New SqlConnection(ConfigurationSettings.AppSettings("MasterConnection"))
        MyCommand = New SqlCommand("SP_My_Buyer", MyConnection)
        MyCommand.CommandType = CommandType.StoredProcedure
        MyCommand.Parameters.Add("@q1", Replace(TextBox1.Text, "'", "''")) ' Company
        MyConnection.Open()
        MyCommand.ExecuteNonQuery()
        MyConnection.Close()
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles    Button1.Click
    NewBuyerSetup()
End Sub
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
G0ggy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
cannase

Thank you for the help.  Do you think this is causing the issue.  Maybe someone keyed in ' and it got by the validator.

Thanks,

Chris
G0ggy

No, the parameter would put pay to SQL Injection attacks.
ASKER
cannase

After further investigation I believe I found the issue.  I was able to replicate the error using the Netscape browser version 9.0.0.6.  When using this version of the browser the validation tools provided by ASP.net failed to work properly.  Required fields are not validated and an error message is displayed e-mail to us.  This is the reason the error randomly occur.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.