how to check white space validation in my viewmodel.cs file in mvc

Viewed 711

i have a property in my EmployeeViewModel.cs as below

[Required]
[RegularExpeession]
public string EmpName {get;set;}

i am maintaining regex for not to allow special characters in my empName

when i give whitespace(press space button 2 times) in my text box the RequiredField validation is not firing because it is considering whitespace as a value

how to check this whitespace issue using required attribue.

could some one help me

2 Answers

You can add another validation to your model called AllowEmptyStrings

[Required(AllowEmptyStrings = false, ErrorMessage = "Please Provide Emp Name")]
[RegularExpeession]
public string EmpName {get;set;}
Related