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.ValidateEmptyText 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 (IsEntryRequired && IsDataPresent ) {
this.IsValid = false;
}
if (IsValid && !IsDatapresent && (this.RegExpression != null ||
this.RegExpression != "")) {
Regex validCheck = new Regex(RegExpression);
this.IsValid = validCheck.IsMatch(this.TextBox1.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 RegularExpressionValidator 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 RegularExpressionValidator? The above regluar expression should also
catch no entry by the user.
I have added a RequiredFieldValidator to solve the problem, but it does not
make sense to have two vlidators for the same textbox: a
RegularExpressionValidator and a RequiredFieldValidator.
Thanks.
--
ASP.NET fan.