same multiple characters - xxxxxxxx

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cribs
Forum Newbie
Posts: 3
Joined: Fri Sep 02, 2005 2:44 pm

same multiple characters - xxxxxxxx

Post by cribs »

having an input form on the web, I keep receiving forms with values of xxxxxxxx, zzzzzzzzzzz etc. I need a way to validate the form and return a error message. Does anyone have any ideas, I know I can not be the only one.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

create a definition of "valid" for each field, then either implement each (as needed) using regular expressions (regex) or simple string analysis.
cribs
Forum Newbie
Posts: 3
Joined: Fri Sep 02, 2005 2:44 pm

here is the code I have to validate name_First form value

Post by cribs »

<?php
switch($key)
{
case 'Date' :
$form_values[$key] = Date("m/d/Y");
break;
case 'name_First' :
$value = ereg_replace (' +', '', $value); // removing spaces in variable
if (empty($value))
{
$message .= 'You did not enter your first name.<br>';
}
else if(preg_match("/[0-9_=*&^%$#@!<>\[\]{}()]/",$value))
{
$message .= ' You entered an incorrect value for your first name.<br>';
}
$form_values[$key] = $value;
break;
}
?>
Post Reply