Search code examples
asp.net-web-apiannotationsdata-annotationswebapi

data annotation showing the same error even while entering same type of data


enter image description here[![enter image description here](https://i.sstatic.net/g7menter image description hereFS.png)](https://i.sstatic.net/g7mFS.png)

Here i tried to use data annotations , i tried to implement Range annotation on salary data type which i declared as a int type but even though i tried to enter data as integer only but still its showing error message (please enter number only) and i have tried executing without data annotations method working successfully but not working with the dataannotation range with this specific type only

HOW CAN SEARCH AND FIND THE PROBLEM TO SOLVE THIS ISSUE


Solution

  • The Regular expression Data Annotation is wrong. Use this instead

    [RegularExpression(@"^[0-9]{4,5}$", ErrorMessage = "Please enter only numbers ")]