473,800 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegularExpressi onValidator problem

I am using a RegularExpressi onValidator to validate a TextBox. I use
"^[\+|-]?[0-9]+(\.[0-9]*)?$" to check for a real number. The control works
fine as long as the user enters something in the TextBox; it does not work if
the user leaves the TextBox blank. Is there a bug in the implementation of
the RegularExpressi onValidator? The above regluar expression should also
catch no entry by the user.

I have added a RequiredFieldVa lidator to solve the problem, but it does not
make sense to have two vlidators for the same textbox: a
RegularExpressi onValidator and a RequiredFieldVa lidator.

Thanks.

--
ASP.NET fan.
Dec 24 '06 #1
4 6057
Hi,
If you are using C# 2.0(Visual Studio 2005) and you want to do your
described validation by using single validator control then you can go for
CustomValidator Control because in ASP.NET 2.0 you can set
CustomValidator .ValidateEmptyT ext property to true.By this Custom Validation
will be performed on empty values also.
If you are using C# 1.0 then you can try following code/logic:

public void Validate() {

this.IsValid = true;

bool IsDataPresent = (this.TextBox1. Trim()==string. Empty );

//check here if control requires entry and does not have one

if (IsEntryRequire d && IsDataPresent ) {

this.IsValid = false;

}

if (IsValid && !IsDatapresent && (this.RegExpres sion != null ||
this.RegExpress ion != "")) {

Regex validCheck = new Regex(RegExpres sion);

this.IsValid = validCheck.IsMa tch(this.TextBo x1.Trim());

}

This Validate Function i have found from the internet.
Hope this helps you out.

Thanks and Regards,
Manish Bafna.
MCP and MCTS.

"curious" wrote:
I am using a RegularExpressi onValidator to validate a TextBox. I use
"^[\+|-]?[0-9]+(\.[0-9]*)?$" to check for a real number. The control works
fine as long as the user enters something in the TextBox; it does not work if
the user leaves the TextBox blank. Is there a bug in the implementation of
the RegularExpressi onValidator? The above regluar expression should also
catch no entry by the user.

I have added a RequiredFieldVa lidator to solve the problem, but it does not
make sense to have two vlidators for the same textbox: a
RegularExpressi onValidator and a RequiredFieldVa lidator.

Thanks.

--
ASP.NET fan.
Dec 24 '06 #2
Thanks for the response. Your response tells me, indirectly, that
RegularExpressi onValidator control has a bug and does not work properly. The
regular expression that I used ( "^[\+|-]?[0-9]+(\.[0-9]*)?$") works
perfectly on the server side but not on the client side when used in
RegularExpressi onValidator control. There are a number of solutions to my
problem, including the ones you sent me. I just wanted to know if I did not
use the control properly or the control is faulty. Based on your answer it is
the control's problem and we have to use another control or work around it.

--
ASP.NET fan.
"Manish Bafna" wrote:
Hi,
If you are using C# 2.0(Visual Studio 2005) and you want to do your
described validation by using single validator control then you can go for
CustomValidator Control because in ASP.NET 2.0 you can set
CustomValidator .ValidateEmptyT ext property to true.By this Custom Validation
will be performed on empty values also.
If you are using C# 1.0 then you can try following code/logic:

public void Validate() {

this.IsValid = true;

bool IsDataPresent = (this.TextBox1. Trim()==string. Empty );

//check here if control requires entry and does not have one

if (IsEntryRequire d && IsDataPresent ) {

this.IsValid = false;

}

if (IsValid && !IsDatapresent && (this.RegExpres sion != null ||
this.RegExpress ion != "")) {

Regex validCheck = new Regex(RegExpres sion);

this.IsValid = validCheck.IsMa tch(this.TextBo x1.Trim());

}

This Validate Function i have found from the internet.
Hope this helps you out.

Thanks and Regards,
Manish Bafna.
MCP and MCTS.

"curious" wrote:
I am using a RegularExpressi onValidator to validate a TextBox. I use
"^[\+|-]?[0-9]+(\.[0-9]*)?$" to check for a real number. The control works
fine as long as the user enters something in the TextBox; it does not work if
the user leaves the TextBox blank. Is there a bug in the implementation of
the RegularExpressi onValidator? The above regluar expression should also
catch no entry by the user.

I have added a RequiredFieldVa lidator to solve the problem, but it does not
make sense to have two vlidators for the same textbox: a
RegularExpressi onValidator and a RequiredFieldVa lidator.

Thanks.

--
ASP.NET fan.
Dec 25 '06 #3
curious wrote:
I am using a RegularExpressi onValidator to validate a TextBox. I use
"^[\+|-]?[0-9]+(\.[0-9]*)?$" to check for a real number. The control
works fine as long as the user enters something in the TextBox; it
does not work if the user leaves the TextBox blank. Is there a bug in
the implementation of the RegularExpressi onValidator? The above
regluar expression should also catch no entry by the user.

I have added a RequiredFieldVa lidator to solve the problem, but it
does not make sense to have two vlidators for the same textbox: a
RegularExpressi onValidator and a RequiredFieldVa lidator.
It does make sense, because that is the way it was designed.

Only the RequiredFieldVa lidator checks for empty fields, so most
of the time you'll need 2 validators. The same for RangeValidators and
CompareValidato rs.

--

Riki

Dec 25 '06 #4
The reason I stated that it does not make sense to have two controls validate
a textbox is because Microsoft calls its control RegularExpressi onValidator.
If it uses regular Expressions to validate a control, it must respond to a
regular expression the standard way, the way any language such as c#, pearl,
etc. respond. Microsoft should not define a new version of regular
expressions for its controls. I have used regular expressions for many years,
and when I use it in an ASP.NET conrol called RegularExpressi onValidator I
expect it to obey the standard rules of regular expressions. It bothers me (
and a lot of other people) when my code does not work as expected and after a
lot of testing I learn that Microsoft has redefined the standard regular
expressions in a control called RegularExpressi onValidator.

Regards.
--
ASP.NET fan.
"Riki" wrote:
curious wrote:
I am using a RegularExpressi onValidator to validate a TextBox. I use
"^[\+|-]?[0-9]+(\.[0-9]*)?$" to check for a real number. The control
works fine as long as the user enters something in the TextBox; it
does not work if the user leaves the TextBox blank. Is there a bug in
the implementation of the RegularExpressi onValidator? The above
regluar expression should also catch no entry by the user.

I have added a RequiredFieldVa lidator to solve the problem, but it
does not make sense to have two vlidators for the same textbox: a
RegularExpressi onValidator and a RequiredFieldVa lidator.

It does make sense, because that is the way it was designed.

Only the RequiredFieldVa lidator checks for empty fields, so most
of the time you'll need 2 validators. The same for RangeValidators and
CompareValidato rs.

--

Riki

Dec 25 '06 #5

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

Similar topics

0
3017
by: Andy Eshtry | last post by:
I have a radio button list, a textbox representing SIN or EIN based on my radio button list selection so I put 2 regularexpressionvalidator to evaluate the value of textbox. EIN must be (for simplicity) with this format (2 digits) like 12 (ValidationExpression="\d{3}-\d{2}") and SIN must be (for simplicity) with this format (3digits-2digits) like 123-45 (ValidationExpression="\d{3}-\d{2}") It works well. The problem is: When I...
3
3798
by: Ricardo Corsi P. Cesar | last post by:
Hi, i looking for example in asp.net (VB) to make the RegularExpressionValidator in runtime in my code behind. I found some similars codes, but nothing in VB.. thanks!
1
3692
by: Ken Grimmett | last post by:
I have added a REV to an input type of file. I want to make sure that the only file type that is allowed is a .gif, .jpg, or .jpeg. I develop my site on my laptop which is running Win XP Pro and my site is hosted on a Win 2000 Advanced server. Here is my problem. When I test it on my local host of the XP Pro machine the validator works. When I migrate it to the W2K box it doesn't work. There is no error that is displayed. Is anyone...
2
2496
by: Enzo Marinelli | last post by:
Hello everyone I have a MultiLine TextBox, as follows <asp:TextBo Id="StreetAddress Rows="4 Runat="Server TextMode="MultiLine Width="100%"/
3
3682
by: tshad | last post by:
I have a RegularExpressionValidator that doesn't seem to work correctly if you don't enter anything. In the following, it works correctly if you have at least 1 character. If you just enter through the field it lets you (even thoug no entry would be less that 6 characters. <asp:textbox id="password1" TextMode="Password" Columns="45" runat="server" /><asp:label text=" 6-20 characters with at least 1 numeric" style="color:red"...
2
1209
by: Sparky Arbuckle | last post by:
I've got a RegularExpressionValidator that partly works. Let me explain: With the Validator below I am only able to search for one letter/number at a time. If I want to search for Diana I see 'Valid Search String', but if I search for A then I see all 113 results. Am I missing something here? <asp:RegularExpressionValidator id="revMenuSearch" ValidationExpression="" ControlToValidate="tbSearch"
1
1849
by: franz | last post by:
does anybody tell me why it doesn't works?? in any case gg beame true thanks franz Dim y As RegularExpressionValidator = New RegularExpressionValidator y.ValidationExpression = "^\w+(\w+)*@\w+(\w+)*\.\w+(\w+)*$" y.ControlToValidate = "ss5ssss" Dim gg As Boolean = y.IsValid
1
1494
by: John Yopp | last post by:
I'm trying to use a asp:RegularExpressionValidator to validate the strength of a password. When I test the regular expression with Regex.IsMatch, it works perfectly. However, when used within a RegularExpressionValidator, it always returns false. Has anyone else had issues with the RegularExpressionValidator not correctly parsing a regular expression? The regular expression I am using is: "^.*(?=.*\d)|(?=.*)|(?=.*)(?=.*)(?=.{8,}).*$"
9
3931
by: Nathan Sokalski | last post by:
I have several TextBoxes with TextMode="MultiLine" in which I want to limit the number of characters that can be entered using a RegularExpressionValidator. I have come up with the following ValidationExpression: {0,250} The only problem with this ValidationExpression is that it does not include the \n character as stated on the following documentation page:
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.