How can I simplify form validation?

前端 未结 11 1507
[愿得一人]
[愿得一人] 2020-12-14 00:57

The code below seems to work pretty well for doing basic required form validation.

The form displays a red Name is required message when the field is dirty

11条回答
  •  盖世英雄少女心
    2020-12-14 01:50

    I'm probably too late for the question, but you could use an external library to handle validation for you. Angular form validator (written by me) makes it easier by having few standard validators in place such as

    1. Required
    2. String (min/max length)
    3. Number (min/max value)
    4. Pattern
    5. Email
    6. Url
    7. Equal to (For verification of email / passwords)
    8. Custom (where you can plug in validation of your own)

    And it allows to combine multiple validators to one field.

提交回复
热议问题