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");
}
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 ThakurPosted May 25, 2017, 2:48 AM
athira kPosted May 25, 2017, 2:19 AM
Dharmraj ThakurPosted May 25, 2017, 12:23 AM
Rajeev PunhaniPosted May 24, 2017, 3:07 PM
If the above solution is helpful then,accept the answer.