Skip to content

Instantly share code, notes, and snippets.

@maskaravivek
Last active August 29, 2015 13:58
Show Gist options
  • Save maskaravivek/10370617 to your computer and use it in GitHub Desktop.
Save maskaravivek/10370617 to your computer and use it in GitHub Desktop.
Function to validate email address
<Style x:Key="TokkriHeaderStyle" TargetType="ContentControl">
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Foreground" Value="{StaticResource TokkriTheme}"/>
<Setter Property="Margin" Value="0,4,0,4"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
<Style x:Key="TokkriTextBox" TargetType="telerikPrimitives:RadTextBox">
<Setter Property="HeaderStyle" Value="{StaticResource TokkriHeaderStyle}"/>
<Setter Property="Height" Value="108"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="WhiteSmoke"/>
<Setter Property="Foreground" Value="Black"/>
</Style>
private bool ValidateEmailID()
{
emailfield.ChangeValidationState(ValidationState.Validating, "validating");
bool isValid = isValidEmail(emailfield.Text);
if (isValid)
{
emailfield.ChangeValidationState(ValidationState.Valid, "great!");
}
else
{
emailfield.ChangeValidationState(ValidationState.Invalid, "Invalid email address!");
}
return isValid;
}
public static bool isValidEmail(string inputEmail)
{
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}
<telerikPrimitives:RadTextBox Name="emailfield" Header="EMAIL" Style="{StaticResource TokkriTextBox}"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment