<pre>asp:TableRow> <asp:TableCell>Email</asp:TableCell> <asp:TableCell> <asp:TextBox runat="server" ID="email" CausesValidation="true"></asp:TextBox> <asp:RequiredFieldValidator runat="server" ID="emailvalidator" ControlToValidate="email" ErrorMessage="Email required" style="color:red"></asp:RequiredFieldValidator> <asp:CustomValidator runat="server" ControlToValidate="email" ErrorMessage="Valid Email required" ValidateEmptyText="True" ClientValidationFunction="validatemail" EnableClientScript="true" OnServerValidate="email_serverValidation"></asp:CustomValidator> </asp:TableCell> </asp:TableRow>
<pre> <script type="text/javascript"> function validatemail(sender,args) { debugger; var val = args.Value; var regex = /^[a-zA-Z0-9]{1-10}@[a-zA-Z]{1-10}.(com|org)$/; if(regex.test(val)) { args.IsValid = true; } } </script>
protected void email_serverValidation(object sender, ServerValidateEventArgs e) { System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("^([a-zA-Z0-9]+)@[a-zA-Z]{1-10}.(com|org)$"); if (r.IsMatch(email.Text)) { e.IsValid = true; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)