Jump to content

PHP Validation


transfield

Recommended Posts

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?
[code]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.
Link to comment
Share on other sites

[code]<?php

for($i=1; $i<=4; $i++)
{
if (in_array(strtoupper($_POST['Text_Box_'.$i]), 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]

Orio.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.