/    Sign up×
Community /Pin to ProfileBookmark

Hello,
I want to validate 4 text boxes(in a html form) to prevent users from keying in certain words. I’m using the code below to validate 1 text box & the code works fine. How do I use the same code to validate all 4 text boxes instead of re-writing the code 4 times?

My code:-

[code=php]if (in_array(strtoupper($_POST[‘Text_Box_1’]), array(’03-‘, ’04-‘, ’05-‘, ’06-‘, ’07-‘, ’08-‘, ’09-‘, ‘012’, ‘013’, ‘016’, ‘017’, ‘019’, ‘E10’, ‘E20’, ‘E30’, ‘RM1’, ‘RM2’, ‘RM3’, ‘RM4’, ‘RM5’, ‘RM6’, ‘RM7’, ‘RM8’, ‘RM9’, ‘012-‘, ‘013-‘, ‘016-‘, ‘017-‘, ‘019-‘))) die(‘This keyword is disallowed. Please click the BACK button of your browser & change your search criteria to something else. Thanks :-)’);[/code]

The names of my text boxes are:-
Text_Box_1
Text_Box_2
Text_Box_3
Text_Box_4

Thanks a lot for your assistance.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 25.2006 — [code=php]
$valid = array('03-', '04-', '05-', '06-', '07-', '08-', '09-', '012', '013',
'016', '017', '019', 'E10', 'E20', 'E30', 'RM1', 'RM2', 'RM3',
'RM4', 'RM5', 'RM6', 'RM7', 'RM8', 'RM9', '012-', '013-',
'016-', '017-', '019-');
foreach(array($_POST['Text_Box_1'], $_POST['Text_Box_2'], $_POST['Text_Box_3'], $_POST['Text_Box_4']) as $field)
{
if (in_array($field, $valid ))
{
die("The keyword '$field' is disallowed. Please click the BACK button of your browser & change your search criteria to something else. Thanks :-)");
}
}
[/code]
Copy linkTweet thisAlerts:
@transfieldauthorOct 25.2006 — I appreciate your help, NogDog. Have a good day!
×

Success!

Help @transfield 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 5.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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