开发者

What language to validate user input?

Im attempting one of my first web applications in PHP.

There is a text box a user inputs text and clicks send. When send is clicked or w开发者_开发百科hen they are typing I want it to give the user an error message if they are entering forbidden characters.

But I cant really see a way to do it effectively in PHP.

Can anyone tell me what programming language would be best for this and maybe links if that would help.

However, I do not want anyone to give me the complete code for this, otherwise there is no challenge in it for me.

Thanks guys


You can use Javascript (with or without jQuery) to realtime validation. Or you use PHP to a server-side validation with IF conditionals.

Javascript Validation Sample:

http://www.w3schools.com/js/js_form_validation.asp

-- EDIT -- I recommend you validate first in the Javascript and later in PHP, because with FireBug users can edit the Javascript validation script.


There are two kinds of validation you need to consider: client-side and server-side.

Client-side validation is when the browser checks the input and reports errors as the user types, or when they hit "submit". You will probably want to use Javascript for this.

Server-side validation is when the server checks the input after the browser has submitted it. You can check this in PHP (or whatever server-side language you want - Java, C# or whatever). Note that you must do server-side validation even if you also do client-side, because you can't trust the user to submit valid data. It's pretty easy to submit bad data even when client-side validation is in use.


You need to use JavaScript because it is a client side language and can detect changed as the user is typing and such.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜