C
cemcat
Hello,
We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to
enter multiple e-mail addresses separated by semicolons. We need to
validate that each individual e-mail address entered is a valid e-mail
address format. We've added a CustomValidator to perform this validation.
We have the server-side validation working fine, but now we need to add some
client-side validation via JavaScript. We are having difficulties with
this.
Here's what we have so far:
<asp:TextBox ID="TextBoxTo" runat="server" ToolTip="To"></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorTo"
runat="server"
ClientValidationFunction="validateTo"
ControlToValidate="TextBoxTo"
Display="Dynamic"
ErrorMessage="Invalid e-mail address or addresses. E-mail address must
be in a standard format ([email protected]). Use a semicolon ( with no
spaces to separate multiple e-mail addresses."
Text="*"
ToolTip="Invalid e-mail address or addresses. E-mail address must be in
a standard format ([email protected]). Use a semicolon ( with no spaces to
separate multiple e-mail addresses."
ValidationGroup="AllValidators"
OnServerValidate="CustomValidatorTo_ServerValidate">
</asp:CustomValidator>
<script type="text/javascript">
function validateTo(oSrc, args)
{
args.IsValid = false;
var formToValidate = document.forms['aspnetForm'];
if (!formToValidate)
{
formToValidate = document.aspnetForm;
}
var controlIndex;
var numberOfControls = formToValidate.length;
var element;
for (controlIndex = 0; controlIndex < numberOfControls;
controlIndex++)
{
element = formToValidate[controlIndex];
if ((element.type == "text") &&
(element.id.lastIndexOf("TextBoxTo") > 0))
{
// First trim any space and/or ; from the front or back of
the text entered in the textbox
// Split the text at every ; to get each individual e-mail
address
// Trim any space and/or ; from each individual e-mail
address
// Use a regular expression to validate each individual
e-mail address
}
}
}
</script>
Can anyone help us figure out the JavaScript code necessary to perform the
validation (see the commented line in the code above)?
Thanks!!!
We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to
enter multiple e-mail addresses separated by semicolons. We need to
validate that each individual e-mail address entered is a valid e-mail
address format. We've added a CustomValidator to perform this validation.
We have the server-side validation working fine, but now we need to add some
client-side validation via JavaScript. We are having difficulties with
this.
Here's what we have so far:
<asp:TextBox ID="TextBoxTo" runat="server" ToolTip="To"></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorTo"
runat="server"
ClientValidationFunction="validateTo"
ControlToValidate="TextBoxTo"
Display="Dynamic"
ErrorMessage="Invalid e-mail address or addresses. E-mail address must
be in a standard format ([email protected]). Use a semicolon ( with no
spaces to separate multiple e-mail addresses."
Text="*"
ToolTip="Invalid e-mail address or addresses. E-mail address must be in
a standard format ([email protected]). Use a semicolon ( with no spaces to
separate multiple e-mail addresses."
ValidationGroup="AllValidators"
OnServerValidate="CustomValidatorTo_ServerValidate">
</asp:CustomValidator>
<script type="text/javascript">
function validateTo(oSrc, args)
{
args.IsValid = false;
var formToValidate = document.forms['aspnetForm'];
if (!formToValidate)
{
formToValidate = document.aspnetForm;
}
var controlIndex;
var numberOfControls = formToValidate.length;
var element;
for (controlIndex = 0; controlIndex < numberOfControls;
controlIndex++)
{
element = formToValidate[controlIndex];
if ((element.type == "text") &&
(element.id.lastIndexOf("TextBoxTo") > 0))
{
// First trim any space and/or ; from the front or back of
the text entered in the textbox
// Split the text at every ; to get each individual e-mail
address
// Trim any space and/or ; from each individual e-mail
address
// Use a regular expression to validate each individual
e-mail address
}
}
}
</script>
Can anyone help us figure out the JavaScript code necessary to perform the
validation (see the commented line in the code above)?
Thanks!!!