简体   繁体   中英

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

I have form who validate user input, I use PHP, Javascript and 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?

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. But never rely on that because evading JavaScript validation is as easy as turning JavaScript off. 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. Javascript is optional for web-users, so go for the sure thing.

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