Add the
RegularExpression attribute[
^] to the property in your model:
[RegularExpression(@"^[^@]+@gmail\.com$", ErrorMessage = "Please enter a GMail address.")]
public string VAREmail { get; set; }
Alternatively, don't let the user type the domain at all:
[RegularExpression(@"^[^@]+$", ErrorMessage = "Please enter a GMail account.")]
public string VAREmail { get; set; }
public string RealEmail
{
get { return string.IsNullOrWhiteSpace(VAREmail) ? string.Empty : VAREmail + "@gmail.com"; }
}
<div class="input-group">
@Html.TextBoxFor(m => m.VAREmail)
<div class="input-group-addon">@gmail.com</div>
</div>