简体   繁体   English

正则表达式:检入PHP(服务器端)或Javascript(客户端)

[英]Regex : Check in PHP (Server-side) or Javascript(client-side)

I have form who validate user input, I use PHP, Javascript and AJAX. 我有验证用户输入的表单,我使用PHP,Javascript和AJAX。 I want to check every field with regex But I'm little confuse about method to check it... 我想用正则表达式检查每个字段,但是我对检查它的方法有点困惑...

What's better method to check it Javascript or PHP? 有什么更好的方法来检查Javascript或PHP?

Thanks in advance.. 提前致谢..

Both. 都。 Use JavaScript for the convenience of the user as you can report an error before they submit the form and have to wait for it to process. 使用JavaScript可以为用户带来便利,因为您可以在他们提交表单之前等待错误报告,然后等待表单处理。 But never rely on that because evading JavaScript validation is as easy as turning JavaScript off. 但是不要依赖于此,因为逃避JavaScript验证就像关闭JavaScript一样容易。 So always validate on the server side, too. 因此,也总是在服务器端进行验证。 If you're only going to use one then it should always be server side validation. 如果您只打算使用一个,那么它应该始终是服务器端验证。

You should always validate user inputs at server-side as you should not trust user-inputs! 您应该始终在服务器端验证用户输入,因为您不应该信任用户输入! Ever that is. 曾经是。 ;) And as a bonus to that you can add client-side validation for user convenience. ;)另外,您可以添加客户端验证以方便用户。

Doing both wouldn't hurt, but make sure PHP is done if you can only do one. 两者都不会造成伤害,但是如果只能做一个,请确保PHP已经完成。 Javascript is optional for web-users, so go for the sure thing. Java脚本对于网络用户是可选的,因此请放心使用。

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

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