简体   繁体   中英

How to handle email input validation in AngularJS with Twitter Bootstrap styling?

Live Demo

Consider an email input:

<input type="email" ng-model="client.email">

If one types a@b in it, client.email stays undefined , but the input is not considered :invalid .

If one uses Bootstrap to style the inputs, this causes the input to have a normal blue outline, rather than the red one, which suggests that the input has a valid email.

This is quite confusing because users think they entered a valid email address, but the underlying model in AngularJS is not set.

Any recommendations how to handle this?

I think your use of Bootstrap is what confused you. If you add the styles yourself for ng-invalid / ng-valid classes, you will see that it's an error.

For instance, the second example at http://docs.angularjs.org/guide/forms demonstrates how you can add custom classes for invalid/valid types, and show that a@b is indeed an invalid value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM