简体   繁体   中英

Use javascript validation on server

In my LAMP application I am using Javascript for form validation but of course internet users can switch Javascript off in their browser so I also validate the form data on the server using a PHP function.

Does anyone know if there is some clever way to reuse my Javascript validation on the server so as to avoid writing a PHP version?

It's a little difficult to tell without knowing how you've constructed your application, but it's unlikely you'll be able to recycle your JavaScript on the server side. On the other hand, if you construct a lightweight, fast php validation tool you can use server-side validation via XHR instead of (a lot of the) JavaScript, and save yourself some redundancy the other direction.

However, that way's bound to be slower, so the best combination of user experience and security will probably come from having some redundancy in your validation.

This might be what you are looking for. It is not a javascript implementation. But this should provide all of your basic validation methods. I do not believe you would be able to find anything close to javascript unless you are using Node.js

Validator.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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