What is the best validation technique or function that I can use to detect spaces,commas or any other characters I dont expect from a user.

I know of ereg and eregi but it seems not to be working the way I want. The problem is that I am allowing a user to create a hall(actually a table in mysql) and if the supplied hall name contains spaces,commas then it results in a mysql error.

Thanks

rony

Recommended Answers

All 2 Replies

You could use ereg like this: (it works as long as there's at least ONE space in the username)

$pattern=" ";

and htmlspecialchars() for changing HTML characters to HTML entities (so HTML/PHP code wont parse/execute on a web page):

echo htmlspecialchars($username);

Do not use ereg or eregi functions, they are being deprecated in PHP5.3. Use preg_replace instead. And if your users' input is resulting in a MySQL error you have MUCH more to worry about than commas. Read up on mysql_real_escape_string

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.