开发者

Validate while user is typing and validate on submit

I validate user input twice actually. While user is typing I check the input to provide some feedback to the user.

开发者_运维技巧

When the user submits the form I validate the input again to check whether the input is correct.

I think using both would cause redundancy and I would like to avoid that.

Is it correct to have just the first validation method? What do you think?


One thing you will definitely miss if you only validate while the user is typing is empty fields.

I think the best of both worlds is to add a "valid" class to valid inputs in your as-you-type validation. Then on submit, skip checking the inputs that have this class.

That said, client-side validation is mainly for the user experience. Server-side validation can always pick up on and notify the user of any errors the client-side validation missed. So it is up to you here to decide how much the client-side validation should do based on your form.


I think you should Just validate on onblur() event for each field (Enough for client side).

And also validate on Server side , can't trust user input .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜