24, July 2008

validate_fields, some suggestions - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Validate_fields Class (Moderator: Olaf)
Topic: validate_fields, some suggestions
« previous next »
Pages: [1] Print

Author Topic: validate_fields, some suggestions  (Read 897 times)
Google dot what?
*
Posts: 2
12 credits
Members referred : 0


« on: Feb 02, 2007, 11:52:02 PM »

This suggestion is very import for all Webmaster:

Check USERNAME FIELD

Code:
function check_username($username, $field, $val, $type = "username", $required = "y"){

if($username == ""){
      $this->messages[] = $this->error_text(1, $field); // emputy
return false;
      }

if(strlen($username) < 5 ){
$this->messages[] = $this->error_text(23, $field); // too sort
return false;
      }

if(!eregi("[a-z]+[0-9]", $username)){
return true;
}else{
$this->messages[] = $this->error_text(22, $field); // not alphanumeric
return false;
}
return true;
}

Check PASSWORD FIELD

Code:
function check_password($password, $field, $val, $type = "password", $required = "y"){

if($password == ""){
      $this->messages[] = $this->error_text(1, $field); // vazio
return false;
      }

if(strlen($password) < 8 ){
$this->messages[] = $this->error_text(19, $field); // too sort
return false;
      }

if(eregi("[a-z]+[0-9]", $password)){
return true;
}else{
$this->messages[] = $this->error_text(20, $field); // alphanumeric
return false;
}
return true;
}

Check if USERNAME OR EMAIL IS IN DATABASE

Code:
function check_datacheck($datacheck, $val, $table, $fieldy, $required = "y"){

global $db;
$field = $val;

if(!get_magic_quotes_gpc()) {
      $datacheck = addslashes($datacheck);
      }
/* $datacheck = valor do campo. */
/* Verify that user is in database */
      $q = "SELECT ".$fieldy." FROM ".$table." WHERE ".$fieldy." = '$datacheck'";
      $result = $db->get_results($q);
      if($db->num_rows < 1){
         return true; //Indicates username is in database
      }else{
$this->messages[] = $this->error_text(21, $field);
return false;
}
}

Check for Brazilian Date dd/mm/aaa

Code:
function check_date($date, $field, $version = "us", $req = "n") {
if ($date == "") {
if ($req == "y") {
$this->messages[] = $this->error_text(1, $field);
return false;
} else {
return true;
}
} else {
$date_parts = explode("/", $date);
$month = $date_parts[1];

if ($version == "pt") {
$pattern = '/^([1-9]|0[1-9]|[12][1-9]|3[01])\D([1-9]|0[1-9]|1[012])\D(19[0-9][0-9]|20[0-9][0-9])$/'; // Brazilian pattern
$day = $date_parts[0];
$year = $date_parts[2];
} else {
$pattern = "/^(19|20)[0-9]{2}[-](0?[1-9]|1[0-2])[-](0?[1-9]|[1-2][0-9]|3[0-1])$/";
$day = $date_parts[2];
$year = $date_parts[0];
}
if (preg_match($pattern, $date) && checkdate(intval($month), intval($day), $year)) {
return true;
} else {
$this->messages[] = $this->error_text(10, $field);
return false;

}
}
}

Sort by $fieldname

Very thanks for this great script.

This is a exemple of previous mentioned:

http://www.screentools.com.br/validate/index.php Visit through proxy
« Last Edit: Feb 02, 2007, 11:54:33 PM by ortlieb »
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


Re: validate_fields :: Future functions and updates
« Reply #1 on: Feb 03, 2007, 12:00:46 AM »

@ortlieb,

do you know this class? http://www.finalwebsites.com/snippets.php?id=10 Visit through proxy

 look, this is a general form field validation class, a user name or password is just a custom text field.

the function that is missing is a universal type validated by a custom regular expression,

in your case its just a regular text field with a length value.

what special with this brazilian date? the slashes?



Last blog : 4th of July Lottery from TemplateMonster.com
Google dot what?
*
Posts: 2
12 credits
Members referred : 0


« Reply #2 on: Feb 03, 2007, 12:25:03 AM »

I Love your validate_fields, I use and is very well...

I think about use in anothers forms with more possibility "Like a global Validate" without access_user_class.

In Brazilian date is used the slashes
I try $version == "eu" and not work for me.

Thanks
Just another rainy day
*
Posts: 1
6 credits
Members referred : 0


« Reply #3 on: Mar 21, 2007, 07:08:28 PM »

This PHP script is nice to use, but would be even better if you could put the reason of a non-valid field. The one I have in head is the number field, that would be nice to tell the user that the field is too long or whatever reason you might have in mind...
But for the rest of it, it's seems to work great!!!

Thanks
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=5904
Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Validate_fields Class (Moderator: Olaf)
Topic: validate_fields, some suggestions
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul 24, 2008, 06:32:36 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 35.708
Total Topics: 7.375
Total Members: 3.705
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: jino@webdco.com

21 Guests, 4 Users online :

13 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.