472,328 Members | 1,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Using Validation controls to check for NON NUMERIC input. (This should be easy!)

I have a textbox control, txtMeasurement, that I want to allow only numeric decimal input. I thought to use a client side validation control to ensure that the data entered is of type "Double".

'Measurement Validation (Range Validator)
Dim MeasurementRangeValidator As New RangeValidator 'validate that the measure is numeric

MeasurementRangeValidator.ControlToValidate = txtMeasurement.ID|
MeasurementRangeValidator.Display = ValidatorDisplay.Dynamic
MeasurementRangeValidator.Type = ValidationDataType.Double|
MeasurementRangeValidator.CssClass = "validatorerrormessage"
MeasurementRangeValidator.MinimumValue = CType(-999999999999, Double).ToString 'essentially allow any value, we are just checking to make sure that it is numeric
MeasurementRangeValidator.MaximumValue = CType(999999999999, Double).ToString

However, if the user types a dash ("-") in the text box, the validation control's edit is passed but my program blows up on the following line:

Dim dblMeasurement as Double = CTYPE(txtMEasurement.Text, Double)

It fails because it is unable to convert a "-" to a Double data type!

By the way, this also does not work:

This function returns TRUE:

BaseCompareValidator.CanConvert("-", ValidationDataType.Double)

but

Dim dblMyDouble As Double = CTYPE("-", Double)

fails!

Is there some way to get the Validation control to fire when and only when the user enters data that cannot be converted to a Double datatype?

Dec 28 '05 #1
2 2812
The RangeValidator only validates once the data is considered well
formatted. In the case of "-", its not a well formatted number.
You need another validator to report a formatting error. That's the
CompareValidator with its Operator=DataTypeCheck and Type=Double

See this article for more on validation: http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Chad" <ch**************@unisys.com> wrote in message
news:do**********@trsvr.tr.unisys.com...
I have a textbox control, txtMeasurement, that I want to allow only numeric
decimal input. I thought to use a client side validation control to ensure
that the data entered is of type "Double".
'Measurement Validation (Range Validator)
Dim MeasurementRangeValidator As New RangeValidator 'validate that the
measure is numeric
MeasurementRangeValidator.ControlToValidate = txtMeasurement.ID|
MeasurementRangeValidator.Display = ValidatorDisplay.Dynamic
MeasurementRangeValidator.Type = ValidationDataType.Double|
MeasurementRangeValidator.CssClass = "validatorerrormessage"
MeasurementRangeValidator.MinimumValue = CType(-999999999999,
Double).ToString 'essentially allow any value, we are just checking to make
sure that it is numeric
MeasurementRangeValidator.MaximumValue = CType(999999999999,
Double).ToString
However, if the user types a dash ("-") in the text box, the validation
control's edit is passed but my program blows up on the following line:
Dim dblMeasurement as Double = CTYPE(txtMEasurement.Text, Double)
It fails because it is unable to convert a "-" to a Double data type!
By the way, this also does not work:
This function returns TRUE:
BaseCompareValidator.CanConvert("-", ValidationDataType.Double)
but
Dim dblMyDouble As Double = CTYPE("-", Double)
fails!
Is there some way to get the Validation control to fire when and only when
the user enters data that cannot be converted to a Double datatype?
Dec 28 '05 #2
Thanks for the response, but I regret to say that your suggestion did
not work.

The result was the same. The Comapre validation control thinks that "-"
or "+" is a valid Double value. However, CTYPE cannot convert it to
store in a Double variable.

*** Sent via Developersdex http://www.developersdex.com ***
Dec 28 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matthias Lohrer | last post by:
Hi, I'm playing around with the possibilities of Page.ParseControl. Thanks to Kirk Allen Evans I got my example running (Posting Juli, 17,...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a web user control (a search menu) which has 2 validation controls (one for input and another for the search...
0
by: buran | last post by:
Dear ASP.NET Programmers, I have a web user control (a search menu) which has 2 validation controls (one for input and another for the search...
2
by: Chris Barrow | last post by:
Hi everyone, Does anyone know if it is possible to append your own javascript function onto the end of a button's onclick method when validation...
3
by: Gareth | last post by:
Hi, I've just published a test web site on the internet with a simple form and some client side validation controls. On my development PC if I...
7
by: Paul | last post by:
Hi, I have a form where a user is required to enter a start date and an end date. Both are required and must between a specific date range (e.g....
2
by: Ing. Rajesh Kumar | last post by:
Hi everybody Validation controls are great but i have a scenario where i do not know how to use them so i am doing my validation on the server....
0
by: Magesh | last post by:
Hi, I have a search screen with a textbox and a button (server controls). The page has to be submitted when the user hits the enter key in the...
2
by: baroque Chou | last post by:
I am using validation controls for input validation, but I would like to know whether the validation occurs at client side or server side, dose...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.