简体   繁体   English

在前端或后端进行现场验证? 哪个更好?

[英]Field validations at frontend or backend? Which is better?

I'm developing a login and registration form using angular-6 as frontend and nodeJs as backend. 我正在开发使用angular-6作为前端和使用nodeJs作为后端的登录和注册表单。 So just want to know which is better, field validation in Angular or in Node? 因此,只想知道在Angular或Node中进行字段验证哪个更好?

It's best to do it on both, frontend and backend. 最好同时在前端和后端上执行此操作。 The backend validation is for security (frontend can be easily faked). 后端验证是出于安全性考虑(前端很容易伪造)。 The frontend validation is for better usability (direct feedback without a roundtrip to the server). 前端验证可提高可用性(直接反馈而无需往返服务器)。

@RajanKumar I will suggest doing field validation on the frontend side because Front-end validation (javascript) can easily be bypassed. @RajanKumar我建议在前端进行字段验证,因为可以轻松地绕过前端验证(javascript)。 It should only be used to improve the "user experience". 它仅应用于改善“用户体验”。 It reduces the load on the server 它减少了服务器上的负载

Use Back-end validation if you required to check the data is coming from frontend side is valid or not for example at the time of signUP check where the email address is already exists or not. 如果您需要检查来自前端的数据是否有效,请使用后端验证,例如,在注册时检查电子邮件地址是否已经存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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