I would like to trim the string or remove whitespaces for the string entered in my textboxfor field called "VAREmail" in mvc. The html code used is
<div class="detailsRow">
<div class="detailsLabel">
@Html.LabelFor(m => m.VarEmail, Strings.VarEmail)
</div>
@Html.TextBoxFor(m => m.VarEmail, new { style = "width:50%" })
@Html.ValidationMessageFor(m => m.VarEmail)
</div>
The controller code triggered when same button is clicked is
[HttpPost]
public ActionResult Edit(Supplier supplier)
{
if (!ModelState.IsValid)
{
supplier = GetSupplier(supplier.SsoId);
return View("Edit", supplier);
}
ReviewerDto dto = googleReviewService.GetReviewerBySsoId(supplier.SsoId);
dto.GoogleReviewEmail = supplier.EmailAddress;
dto.MorpheusId = supplier.MorpheusId;
dto.VarEmail = supplier.VarEmail;
dto.SesameEmail = supplier.SesameEmail;
dto.SesameFirstName = supplier.SesameFirstName;
dto.SesamePassword = supplier.SesamePassword;
dto.VettedReviewer = supplier.VettedReviewer;
googleReviewService.UpdateReviewer(dto);
supplier
.ReviewerRates
.ToList()
.ForEach(rr => googleReviewService.SetReviewerRateActiveStatus(supplier.SsoId, rr.RateId, rr.Active));
return RedirectToAction("List");
}
the model used with some regular expression fro validation is
[StringLength(50)]
[RegularExpression(@"^(?i)[A-Z0-9._%+-]+@[A-Z0-9]+.com", ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ReviewerEditModel_InvalidEmailEntered")]
[Display(ResourceType = typeof(Strings), Name = "VarEmail")]
public string VarEmail { get; set; }
can anyone please help me to fix this bug.
What I have tried:
tried using trim() in both view and controller