98c28fcbe1e816f8e64ff24302298e81

I am trying to wrap my head around creating a reusable validation. I came up with the following pretty much inspired by a book written by Reiersol. You can find the full code library on http://code.google.com/p/validation-php/

The code is the example usage of the open source validation library.

// example code for usage of the validation library
// find library code at http://validation-php.googlecode.com/svn/trunk/src/Validator/

$request = new Request_Raw(array('username' => 'testervih.dk'));

$validator = new Validator;
$validator->addBasicValidator(new Rule_Email('username'), 'email is not valid');

if (!$validator->validate($request)) {
    print_r($validator->getErrors());
} else {
    echo $validator->getCleanRequest()->get('username');
}

Refactorings

No refactoring yet !

08b49e3d543f221ed51cdbe118448275

zaadjis

October 12, 2007, October 12, 2007 07:53, permalink

1 rating. Login to rate!
<?php

if (!filter_var('bob@example.com', FILTER_VALIDATE_EMAIL)) {
    $errors[] = 'email invalid';
}
98c28fcbe1e816f8e64ff24302298e81

lsolesen

October 12, 2007, October 12, 2007 08:06, permalink

No rating. Login to rate!

I was not trying to reinvent google. I was trying to operate with a raw request and a clean request (making sure that all values which I use in my app. has been validated).

And I am trying to learn :)

4b03f479e355368107c8b09b51c2b70a

Juan

October 12, 2007, October 12, 2007 15:14, permalink

1 rating. Login to rate!
?<php 


     re-stat:aced
D41d8cd98f00b204e9800998ecf8427e

juan

October 12, 2007, October 12, 2007 15:15, permalink

1 rating. Login to rate!

never mind thats wrong

Your refactoring





Format Copy from initial code

or Cancel