/    Sign up×
Community /Pin to ProfileBookmark

PHP input field validation

Hello

This night I tried everything I could think of / find on the internet . No success ?

What I want to do is to validate a field . If it contains the symbols “<” or “>” I need it to return a error .
Also , if it contains “www” , “.com” , “.XXX” to return a error too .

Is there anyone experienced with validation that can help me ?

What I got ( and i think it was closest to the right one ) was this :

[code=php]if ($input == NULL || $input == “something”){
$input_error = “You must type a something first ! “;
}else if (preg_match(‘/></’, $input)) {
$input_error = “You have invalid characters in your phrase.”;
}else{
$displayer_create = mysql_query(“INSERT INTO `DB` (`id`,`content`) VALUES (”,’$input’)”);
};};[/code]

Tried to do it with ” preg_match(“/[^<>]+$”,$input) ” , no luck either .

Thank you in advance

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 12.2010 — If you're concerned about HTML tags, here's a quick way:
[code=php]
if(strip_tags($string) != $string) {
// reject it
}
[/code]


Also, you appear to have an extra "}" at the end of your code sample. (BTW, the ";" after the closing "}" is unnecessry.)
Copy linkTweet thisAlerts:
@maernauthorOct 12.2010 — Yeah , that } was from


if(isset($_POST['submit'])){

^^^earlier paste

vvvv

};};

I will try with the strip_tags now. Thank you for the fast reply .
Copy linkTweet thisAlerts:
@maernauthorOct 12.2010 — Put it up , worked like a charm .

I was concerned about the <script> tags more than anything else .

Thank God I got this solved ?

Thank you !
Copy linkTweet thisAlerts:
@NogDogOct 12.2010 — Your regexp probably would have worked if you put the angle brackets into a character class:
[code=php]
'/[<>]/'
[/code]

Otherwise you were looking for the exact character sequence "><" instead of any occurrence of either character.
Copy linkTweet thisAlerts:
@maernauthorOct 12.2010 — The arrowhead problem has been solved , but can someone tell me how to block them from using certain words ?

for example, to return false if any of the words from an array or string exists in the input .

If www exists , return false

If n*gg* exists , return false

and stuff like that

Thank you in advance .
×

Success!

Help @maern spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...