I normally store phone numbers as 10 digits in the database. However, I want to use a jQuery masked input plugin to guide the user with a mask like this: (_) -___. Unfortunately, my StringLength attribute fails as well as my \d{10} regex attribute on the client. I can create my own custom phone validator attribute, but it's always trumped by the other attributes. Is there a way to pick and choose which validators are done client-side? I'm using code-first so I definitely want my StringLength attributes to stay on my model. I just don't want them always participating in client validation.
Asked
Active
Viewed 375 times
1 Answers
1
If you can disable the client side validation for this property and maybe implement something yourself then you could consider a custom model binder that is attached to just this property (see here) and strip out the extra bits of data before it hits your model.

Community
- 1
- 1

aaronrhodes
- 615
- 5
- 10