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.