Hey guys I am working on a project in webmatrix that requires a user to register there details. The first box is their email address. Basically I need a bit of help nailing down the regular expressions.
Ive got a file called validation.cshtml in main folder with the following function:
@functions {
public static bool IsValidEmail(string value)
{
const string expression = @"^([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})(\]?)$";
return Regex.IsMatch(value, expression);
}
}
Then I call the function in the register.cshtml page, but here is where i am going wrong. I am not sure how to write the function. Here is what I have
if (!Validation.IsMatch(email))
{
ModelState.AddError("email", "The Email Address Must contain the @ sign");
}
I have "email" here because this is the variable name for the email textfield.