Hi
Try this,
I could noe understand ur requirement. Their are two ways to validate the Controls they are 1. Client-Side Validation and 2. Server-Side Validation.
1. Client Side Validation: using the Required Field Validator and RegularExpression Validator. the following sample code is help ful for u.
<asp:TextBox ID="txtAddress1" Text="" size="30" MaxLength="100" CssClass="Black08" runat="server"/>
<asp:RequiredFieldValidator ID="rfvAddress1" runat="server" ControlToValidate="txtAddress1"
ErrorMessage="Please enter ADDRESS (1)" ForeColor="Red" ValidationGroup="Group1"
Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revAddress1" runat="server" ErrorMessage="Enter valid ADDRESS (1)"
ControlToValidate="txtAddress1" ForeColor="Red" ValidationExpression="^((?:[A-Za-z0-9-'.,\s]+|&[^#])&?)$"
Display="Dynamic"></asp:RegularExpressionValidator>
2. Server-Side Validation using the Regex class Expression
if (!string.IsNullOrEmpty(txtAddress1.Text))
{
if (!Regex.IsMatch(txtAddress1.Text.Trim(), @"^([\w\d\s\-\'\.\,]*)$"))
{
revAddress1.IsValid = false;
revAddress1.ErrorMessage = "Enter valid ADDRESS(1)";
}
else
{
revAddress1.IsValid = true;
}
N. MOHAMED ZACKKARIAH
Rrana, if this helps please login to Mark As Answer. | Alert Moderator