Joerg Jooss (5) [Avatar] Offline
#1
Table 8.1 shows PhoneNumber as validation attribute, but the attribute is actually called [Phone] (i.e. System.ComponentModel.DataAnnotations.PhoneAttribute.

Aside: Is [Phone] really used for validation? I see neither client side nor server side validation being used for a binding model with a [Phone] property (assuming 'asgdsg' doesn't qualify as valid phone number smilie). The same is true for DataType(DataType.PhoneNumber).
Andrew Lock (9) [Avatar] Offline
#2
Thanks for picking that up, it should be
PhoneAttribute
, not
PhoneNumber
!

The attribute should be used for validation on the server side at least (you can see the source code for it here: https://github.com/dotnet/corefx/blob/v1.1.1/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/PhoneAttribute.cs)

I'll do some additional tests, and get back to you once I've confirmed
Joerg Jooss (5) [Avatar] Offline
#3
As I said, I've tested this already--it doesn't validate in ASP.NET Core MVC, nor does it in MVC 5. Or I'm doing something wrong smilie
Andrew Lock (9) [Avatar] Offline
#4
I've just double checked this, and the [Phone] attribute definitely validates correctly server side, but it doesn't include client side validation. You can see a working example if you look at the source code for the book and take a look at the chapter06/ValidatingWithDataAnnotations project.

Hopefully that will help!
Andrew
Joerg Jooss (5) [Avatar] Offline
#5
After fiddling with your sample, I found that a stumbled across a string of errors I had made that more or less hid the validation error.

Another thing I realized is that the integration with Bootstrap's form related classes has to be done manually. That's something that might be worth mentioning in section 6.3.4. (see the attached screenshot and how invalid fields are highlighted, whereas there's no additional visual cue on the input elements in figure 6.9 and 6.10).