controller
if (!string.IsNullOrEmpty(student.FirstName))
{
string nameRegex = @"^([a-zA-Z ])+$";
Regex re = new Regex(nameRegex);
if (!re.IsMatch(student.FirstName))
{
ModelState.AddModelError("FirstName", "FirstName only be letters");
}
}
else
{
ModelState.AddModelError("FirstName", "FirstName is required");
}
Code
I have given validation in regular expression Like this in controller part
I need to give validation for name that it should accept only letters and numbers and no special characters
model
I need to give validation for name that it should accept only letters and numbers and no special characters
model
public string FirstName { get; set; }
how can I do this ?? can anyone please help me to do this ?

Dharmraj ThakurRank #577 · 4.2K reputationPosted May 24, 2017, 10:48 PM EDT
Rajeev PunhaniRank #551 · 4.4K reputationPosted May 24, 2017, 11:07 AM EDT
If the above solution is helpful then,accept the answer.
Dharmraj ThakurRank #577 · 4.2K reputationPosted May 24, 2017, 8:23 PM EDT
athira k131 reputationPosted May 24, 2017, 10:19 PM EDT