在哪里清理用户提交的数据?
用户可以提交调色板,我想标准化提交的十六进制代码的格式。
是否有一种典型的方法来清理/标准化此类用户提交的数据?
就我而言,用户可以在四个字段中输入十六进制代码。我最终想在没有井号的情况下存储它。 (因此从 #000000
到 000000
)。
删除井号显然很容易,但我不确定它应该在过程中的什么位置。
需要在服务器端,因为该数据可以通过浏览器以外的其他方法(即 API)提交。
Users can submit color palettes and I'd like to standardize the format of the hex codes submitted.
Is there a typical way to clean up/standardize this sort of user-submitted data?
In my case, there are four fields where users can enter a hex code. I ultimately want to store it without the pound sign. (So #000000
to 000000
).
It's obviously easy to remove the pound sign, but where in the process it should be is what I'm not sure of.
Needs to be server-side as this data can be submitted via other methods than the browser (i.e. API).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
到处!
您肯定希望在服务器端清理它,因为(大概)这是任何期望格式一致的数据出现的处理的地方,也是您清理用户输入的地方(您正在这样做,当然,对吧?)。不要信任服务器上远程来源的任何内容!
不过,一点客户端自动格式化也没什么坏处。使用 javascript 自动格式化内容并在执行时给您的用户留下深刻印象!
Everywhere!
You'll definitely want to clean it up server-side, as that's (presumably) where any sort of processing that expects consistently-formatted data to appear, and that's also where you'll be sanitizing user input (which you're doing, of course, right?). Don't trust anything from a remote source on a server!
A bit of client-side auto-formatting wouldn't hurt, though; use javascript to automatically format things and impress your users while doing it!
为什么不在将数据传递给任何东西之前使用Javascript来清理数据?在将字符串提交给控制器/操作之前,您应该能够轻松地评估该字符串并进行调整。
Why not use Javascript to sanitize the data before passing it through to anything? You should be able to easily evaluate the string and make adjustments there before submitting it to your controller/action.