Im building an API which requires some mandatory parameters to be POSTed to it.There are about 15 mandatory parameters which should be passed to the api,I wanted to show relevant errors to the developer if there is any parameter missing like "Could not process ; email parameter is missing ".
I have already implemented the logic,but its not working well and seems to be very badly coded with excess codes.This is the current approach
if ($data['email'] AND array_key_exists('email', $data)) {
if (!validateEmail($data['email'])) {
$transaction_error = 'Invalid email';
}
} else {
$transaction_error = 'Parameter email is missing';
}
if (!($data['addr'] AND array_key_exists('addr', $data))) {
$transaction_error= 'Parameter addr is missing';
}
if (array_key_exists('show_shipping_addr', $data)) {
if (!verifyBinary($data['show_shipping_addr'])) {
$transaction_error = 'Invalid show_shipping_addr';
}
} else {
$transaction_error = 'Parameter show_shipping_addr is missing';
}
if (array_key_exists('authorize_user', $data)) {
if (!verifyBinary($data['authorize_user'])) {
$transaction_error = 'Invalid authorize_user';
}
} else {
$transaction_error = 'Parameter authorize_user is missing';
}
if ($data['mobileNo'] AND array_key_exists('mobileNo', $data)) {
if (!validateMobileNo($data['mobileNo'])) {
$transaction_error = 'Invalid mobileNo';
}
} else {
$transaction_error = 'Parameter mobileNo is missing';
}
if ($data['currency_code'] AND array_key_exists('currency_code', $data)) {
if (!validateCurrencyCode($data['currency_code'])) {
$transaction_error = 'Invalid currency_code';
}
} else {
$transaction_error = 'Parameter currency_code is missing';
}
if ($data['checksum_method'] AND array_key_exists('checksum_method', $data)) {
if (!validateChecksumMethod($data['checksum_method'])) {
$transaction_error = 'Invalid checksum_method';
}
} else {
$transaction_error = 'Parameter checksum_method is missing';
}
if ($data['zipcode'] AND array_key_exists('zipcode', $data)) {
if (!validateZipCode($data['zipcode'])) {
$transaction_error = 'Invalid zipcode';
}
} else {
$errors[$i++] = 'Parameter zipcode is missing';
}
if ($data['f_name'] AND array_key_exists('f_name', $data)) {
if (!validateAlphaString($data['f_name'])) {
$transaction_error = 'Invalid name';
}
} else {
$transaction_error = 'Parameter f_name is missing';
}
if ($data['state'] AND array_key_exists('state', $data)) {
if (!validateAlphaString($data['state'])) {
$transaction_error = 'Invalid state';
}
} else {
$transaction_error = 'Parameter state is missing';
}
if ($data['country'] AND array_key_exists('country', $data)) {
if (!validateAlphaString($data['country'])) {
$transaction_error = 'Invalid country';
}
} else {
$transaction_error = 'Parameter country is missing';
}
if ($data['city'] AND array_key_exists('city', $data)) {
if (!validateAlphaString($data['city'])) {
$transaction_error = 'Invalid city';
}
} else {
$transaction_error = 'Parameter city is missing';
}
/* Validation of mandatory parameters ends here */
/* Validation of optional parameters starts here
*shipping_email
*shipping_mobileNo
*shipping_zipcode
*l_name
*shipping_addr
*shipping_city
*shipping_state
*shipping_country
*surl
*furl
*rurl
*/
if (array_key_exists('l_name', $data)) {
if (!validateAlphaString($data['l_name'])) {
$transaction_error = 'Invalid l_name';
}
}
if (array_key_exists('shipping_addr', $data)) {
if (!$data['shipping_addr']) {
$transaction_error = 'Parameter shipping_addr is missing';
}
}
if (array_key_exists('shipping_mobileNo', $data)) {
if (!validateMobileNo($data['shipping_mobileNo'])) {
$transaction_error = 'Invalid shipping_mobileNo';
}
}
if (array_key_exists('shipping_city', $data)) {
if (!validateAlphaString($data['shipping_city'])) {
$transaction_error = 'Invalid shipping_city';
}
}
if (array_key_exists('shipping_state', $data)) {
if (!validateAlphaString($data['shipping_state'])) {
$transaction_error = 'Invalid shipping_state';
}
}
if (array_key_exists('shipping_country', $data)) {
if (!validateAlphaString($data['shipping_country'])) {
$transaction_error = 'Invalid shipping_country';
}
}
if (array_key_exists('shipping_zipcode', $data)) {
if (!validateZipCode($data['shipping_zipcode'])) {
$transaction_error = 'Invalid shipping_zipcode';
}
}
if(isset($api_error)) // IF there are API error pages are rendered
{
$api_error_array['api_error'] = $api_error;
$this->render_api_errors($api_error_array);
}
else if (isset($transaction_error)) { //If there are transactional errors,user is redirected back to mercahnt response url
$api_data = $this->paymentgateway->getAPIData($data['app_used'], $data['apikey']);
$data['response_url'] = $api_data['response_url'];
$data['transaction_errors'] = $transaction_error;
$this->paymentgateway->logApiRequest($data['app_used'], $transaction_error, 'Notice', $data['ip_address'], $data['ip_address_customer']);
$this->redirect_transactional_error($data);
} else {
$this->process($data); //Calls the process function when everything is done
}
I have got some set of mandatory fields and some set of non mandatory fields.The non mandatory fields if set need to be checked for their validity.
Please suggest a convienient way for validating post requests without making the code heavy.I have seen the following codes
if($_SERVER['REQUEST_METHOD'] != "POST")
die("Error: Wrong method");
$fields = array("f1", "f2", "f3", "f4");
$field_names = array("field1", "field2", "field3", "field4");
$length = count($fields);
$missing_input = array();
for($i = 0; $i < $length; $i++)
if(empty($_POST[$fields[$i]]))
$missing_input[] = $field_names[$i];
if(!empty($missing_input))
die("Error: " . implode(", ", $missing_input)");
from SO which makes sense.Can some suggest me a best practice of validating mandatory parameter in an API and showing relevant errors based on that?Instead of validating each paramters individually,can i make a single function whcih will check for the paramters and show the errors?
You can create one array of fields name which need to be mandatory / validated
$validate = array(
'username' => array('mandatory' => true, 'regex' => '/^[a-z0-9_-]{3,16}$/'),
'password' => array('mandatory' => true, 'regex' => null),
// Same like the above example you can create all validation
)
$missing_input = array();
foreach($_POST as $key => $val){
$mandatory = isset($validate[$key]) ? $validate[$key] : false;
if($mandatory && !trim($val)){
// Manage error here
$missing_input[] = $key;
}
// Same like above get the regex and validate the field here and manage the error
}
// Return / Print error array
if(!empty($missing_input))
die("Error: " . implode(", ", $missing_input)");
you can also define the min and max limit in the $validate array and inside the foreach loop validate accordingly, simple logic to validate asper your requirement.
$validate = array(
'username' => array('mandatory' => true, 'regex' => '/^[a-z0-9_-]{3,16}$/'),
'password' => array('mandatory' => true, 'regex' => null),
// Same like the above example you can create all validation
)
$missing_input = array();
$invalid_input = array();
foreach($_POST as $key => $val){
$mandatory = isset($validate[$key]['mandatory']) ? $validate[$key]['mandatory'] : false;
$regex = isset($validate[$key]['regex']) ? $validate[$key]['regex'] : null;
if($mandatory && !trim($val)){
// Manage error here
$missing_input[] = $key;
} else if($regex != null && trim($val)){
if(!preg_match($regex,$val)){
$invalid_input[] = $key;
}
}
}
// Return / Print error array
if(!empty($missing_input))
die("Missing Inputs: " . implode(", ", $missing_input). "Invalid Inputs" . implode(", ", $invalid_input));
$data = array('addr'=>'test','mobileNo'=>'test');//only for test
$dataMandatory = array('email'=>1,'addr'=>1,'mobileNo'=>1);//array of mandatory field
$transaction_error=array();//array to contain error
foreach($data as $key=>$value){
if (array_key_exists($key, $dataMandatory)) {
unset($dataMandatory[$key]);
if(!call_user_func('validate'.ucfirst($key), $value)){//i call valide method
$transaction_error[] = 'Invalid '.$key;
}
}
}
if(count($dataMandatory)!==0){
$transaction_error[] = 'Parameter missing : '.implode(',',array_flip ($dataMandatory));
}
Pros : only on array to change for add mandatory field, no duplicate code
Cons : u cant change function name (valideKey) and custom treatment
Related
I'm setting up a rest-API on my server, and I want to update a table (i.e "comp_holding_stock"). but every time I test to post new data it returns "No item found"
Here is my controller
public function create_comp_holding_stock(){
$returnArr['status'] = '0';
$returnArr['response'] = '';
try {
if (!$this->input->post()) {
$returnArr['response'] = "Only POST method is allowed";
} else {
$holding_stock_data = array(
'comp_id' => $this->input->post('comp_id'),
'customer_id' => $this->input->post('customer_id'),
'quantity' => $this->input->post('quantity'),
'date' => date('Y-m-d H:i:s')
);
if (!isset($holding_stock_data)) {
$returnArr['response'] = "Some Parameters are missing";
} else {
$customer = $this->Customer->save_holding_stock($holding_stock_data);
if (!$customer) {
$returnArr['response'] = 'No items found';
} else {
$returnArr['status'] = '1';
$returnArr['response'] = $customer;
}
}
}
} catch (Exception $ex) {
$returnArr['response'] = "Error in connection";
$returnArr['error'] = $ex->getMessage();
}
$response = json_encode($returnArr, JSON_PRETTY_PRINT);
echo $response;
}
And here is my model below
public function save_holding_stock($holding_stock_data)
{
// $this->db->trans_start();
$success = $this->db->insert('comp_holding_stock', $holding_stock_data);
return $success;;
}
what am i doing wrong? what is the best approach to this scenarios
I would recommend try to check if you have load model in your controller.
And in your model try to do this.
public function save_holding_stock($holding_stock_data, $comp_id=FALSE)
{
if(!$comp_id == -1 || !$this->exists($comp_id))
{
if($this->db->insert('comp_holding_stock', $holding_stock_data))
{
$holding_stock_data['comp_id'] = $this->db->insert_id();
return TRUE;
}
return FALSE;
}
$this->db->where('comp_id', $comp_id);
return $this->db->update('comp_holding_stock', $holding_stock_data);
}
Try these changes in your code
In your controller,
$customer = $this->Customer->save_holding_stock($holding_stock_data);
$save_status = $this->db->affected_rows();
if ($save_status>0) {
$returnArr['status'] = '1';
$returnArr['response'] = $customer;
} else {
$returnArr['response'] = 'No items found';
}
In your model,
public function save_holding_stock($holding_stock_data)
{
// $this->db->trans_start();
$this->db->insert('comp_holding_stock', $holding_stock_data);
}
I made a captcha login it is working so far but there is two problem and that problem is that first, when your username or password is wrong the page went to blank. Second, when both of the username,password and captcha are wrong the page went blank
but when your username and password are correct and the captcha is wrong it will call the echo'captcha is not correct';
function aksi_login(){
$data = array('username' => $this->input->post('username', TRUE),
'password' => md5($this->input->post('password', TRUE))
);
$this->load->model('m_model'); // load model_user
$hasil = $this->m_model->cek_user($data);
if ($hasil->num_rows() == 1 && $this->input->post('submit')){
$inputCaptcha = $this->input->post('captcha');
$sessCaptcha = $this->session->userdata('captchaCode');
if($inputCaptcha === $sessCaptcha){
foreach ($hasil->result() as $sess) {
$sess_data['logged_in'] = 'Sudah Login';
$sess_data['id_user'] = $sess->uid;
$sess_data['username'] = $sess->username;
$sess_data['level'] = $sess->level;
$this->session->set_userdata($sess_data);
}
if ($this->session->userdata('level')=='1') {
redirect('admin');
}
elseif ($this->session->userdata('level')=='2') {
redirect('guru');
}
elseif ($this->session->userdata('level')=='3') {
redirect('siswa');
}
else {
echo'username or password is wrong'
}
}
else{
echo "captcha code is not correct";
}
}
}
I think so far is because of the controller code and i have made some changes I tried putting another elseif like
elseif ($this->session->userdata('username')== FALSE && $this->session->userdata('password')==FALSE){
echo'username or password is wrong';
}
else {
echo'username or password is wrong';
}
but unfortunately is not working
Its better to check for captcha first in a separate condition then check for validation, so if you got everything right and your post values are all ok then you should do it like this:
if (this->captcha_validation($this->input->post('captcha')))
{
$this->form_validation->set_rules($this->rules);
if ($this->form_validation->run() === TRUE)
{
$username = $this->input->post('username');
$password = $this->input->post('password');
// your magic
}
else
{
// array of validation errors
validation_errors = $this->form_validation->error_array();
}
}
else
{
// wrong captcha
$this->recaptcha();
}
Now you have isolated the two checks and made it way easier for recaptcha, but more importantly you don't need to make form validation if the captcha is wrong in the first place.
...
Not sure how your code works but in // your magic up there put your logic like this:
$this->load->model('m_model'); // load model_user
$hasil = $this->m_model->cek_user($data);
if ($hasil->num_rows() > 0)
{
foreach ($hasil->result() as $sess)
{
$sess_data['logged_in'] = 'Sudah Login';
$sess_data['id_user'] = $sess->uid;
$sess_data['username'] = $sess->username;
$sess_data['level'] = $sess->level;
$this->session->set_userdata($sess_data);
}
if ($this->session->userdata('level') == '1')
{
redirect('admin');
}
elseif ($this->session->userdata('level') == '2')
{
redirect('guru');
}
elseif ($this->session->userdata('level')=='3')
{
redirect('siswa');
}
}
My suggestion to to rewrite your controller and use Form Validation as it is also codeigniter standard library
Check the official documentation here
https://www.codeigniter.com/userguide3/libraries/form_validation.html
//your validation config should be something like this
public function login() {
$form_rules = [
[
'field' => 'username',
'label' => 'Username',
'rules' => 'required',
],
[
'field' => 'password',
'label' => 'Password',
'rules' => 'required',
],
[
'field' => 'captcha',
'label' => 'No HP',
'rules' => 'rules' => 'required|callback_check_captcha'
],
];
$this->form_validation->set_rules($this->form_rules);
if ($this->form_validation->run() == TRUE) {
//check username & password
//if you're sure that username is unique, you can directly get 1 data with ->row()
$check = $this->m_model->cek_user($data)->row();
if($check) {
switch($check->level) {
case '1' :
break;
case '2' :
......
......
}
} else {
//wrong username / password
}
} else {
//show login form with view
}
}
/*callback fro form validation*/
public function check_captcha($str) {
if(!empty($this->session->cap_word)) {
$expiration = time() - $this->config->item('captcha_expiration');
if($this->session->cap_time > $expiration) {
if($this->session->cap_word == $str) {
return TRUE;
} else {
$this->form_validation->set_message('check_captcha', 'Wrong captcha.');
return FALSE;
}
} else {
$this->form_validation->set_message('check_captcha', 'Session captcha expired.');
return FALSE;
}
} else {
$this->form_validation->set_message('check_captcha', 'KWrong captcha.');
return FALSE;
}
}
I've created a registering form, and I'd like to validate user input, for security purposes.
I've created some functions, shown below.
I am just unsure on how to implement them correctly. Do I nest if statements? Do I just keep it like I have it now?
How do I stop my script when something isn't right? To prevent an insert from even being tried when something isn't right.
Any help is greatly appreciated.
function validateLength($stringToValidate, $minimumLength) {
if(strlen($stringToValidate) < $minimumLength) {
return [
'error' => 'Minimum length is 8 charachters',
'class' => 'alert alert-danger',
];
} else {
return true;
}
}
function validateEmail($emailToVerify) {
if(filter_var($emailToVerify, FILTER_VALIDATE_EMAIL)) {
return true
} else {
return [
'error' => '<strong>Error:</strong> That is not a valid email address',
'class' => 'alert alert-danger'
];
}
}
function formIsFilledIn(array $formInputs = []) {
foreach ($formInput as $inputField) {
if(empty($inputField)) {
return [
'error' => '<strong>Error: </strong> Fill in all fields.',
'class' => 'alert alert-danger',
];
}
}
return null;
}
Now, I'm using every function like so.
$formErrors = formIsFilledIn($_POST);
if($formErrors !== null) {
// Something is not filled in
}
$formErrors = validateLength($_POST['username'], 8);
if($formErrors !== true) {
// Username doesn't have enough characters
}
$formErrors = validateLength($_POST['password'], 8);
if($formErrors !== true) {
// Password doesn't have enough characters
}
For completeness, this is the insert part (it works properly)
$stmt = $connect->prepare('INSERT INTO `users` (user_name, user_password, user_email, user_perms, user_created_at) VALUES (?, ?, ?, ?, ?)');
if($stmt) {
$username = $_POST['username'];
$password = hashPassword($_POST['password']);
$email = $_POST['email'];
$date = date('Y-m-d H:i:s');
$perms = "Gebruiker";
$stmt->bind_param('sssss', $username, $password, $email, $perms, $date);
if($stmt->execute()) {
$err = "<strong>Success: </strong> The account has been created";
$class = "alert alert-success";
} else {
$err = "<strong>Error:</strong> Something went wrong";
$class = "alert alert-danger";
}
}
You could indeed chain the if's together using elseif. I would however suggest some changes to the functions. Instead of letting them validate and return an array containing some errors, you'd need to only let them validate and return either true or false
It would look somewhat like this:
function validateLength($stringToValidate, $minimumLength) {
if(strlen($stringToValidate) < $minimumLength) {
return false;
} else {
return true;
}
}
function validateEmail($emailToVerify) {
if(filter_var($emailToVerify, FILTER_VALIDATE_EMAIL)) {
return true;
} else {
return false;
}
}
function formIsFilledIn(array $formInputs = []) {
foreach ($formInputs as $inputField) {
if(empty($inputField)) {
return false;
}
}
return true;
}
This means that you can do the following:
if(!formIsFilledIn($_POST)) {
$error = [
'error' => '<strong>Error: </strong> Fill in all fields.',
'class' => 'alert alert-danger',
];
} elseif(!validateLength($_POST['username'], 8) || !validateLength($_POST['password'], 8)) {
$error = [
'error' => 'Minimum length is 8 charachters',
'class' => 'alert alert-danger',
];
}
elseif(!validateEmail($_POST['email'])) {
$error = [
'error' => '<strong>Error:</strong> That is not a valid email address',
'class' => 'alert alert-danger'
];
}
else {
// now you can call a function that starts to insert stuff, everything has been validated
}
Of course, this would becomes longer the longer the form will get. An other option would be to iterate over the post and check if all fields have a valid length. When that is done you can check the email and all other special fields
I am not sure if this question has been answered in round about ways through other questions but...
I am creating a web page for my job which has multiple entry fields (all of which have the same validation code). The following is a small section of my php code:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["bottomair"])) {
$bottomairerror = "Maketable bottom air temp is required";
} else {
$bottomair = test_input($_POST["bottomair"]);
if (!filter_var($bottomair, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax)))) {
$bottomairerror = $errormsg;
}
}
if (empty($_POST["topair"])) {
$topairerror = "Maketable top air temp is required";
} else {
$topair = test_input($_POST["topair"]);
if (!filter_var($topair, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax)))) {
$topairerror = $errormsg;
}
}
if (empty($_POST["meat"])) {
$meaterror = "Maketable meat temp is required";
} else {
$meat = test_input($_POST["meat"]);
if (!filter_var($meat, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax)))) {
$meaterror = $errormsg;
}
}
if (empty($_POST["cheese"])) {
$cheeseerror = "Maketable cheese temp is required";
} else {
$cheese = test_input($_POST["cheese"]);
if (!filter_var($cheese, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax)))) {
$cheeseerror = $errormsg;
}
}
if (empty($_POST["walkin"])) {
$walkinerror = "Walk-In temp is required";
} else {
$walkin = test_input($_POST["walkin"]);
if (!filter_var($walkin, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax)))) {
$walkinerror = $errormsg;
}
}
if (empty($_POST["refrig1"])) {
$refrig1error = "Refrigerator #1 temp is required";
} else {
$refrig1 = test_input($_POST["refrig1"]);
if (!filter_var($refrig1, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax)))) {
$refrig1error = $errormsg;
}
}
if (empty($_POST["refrig2"])) {
$refrig2error = "Refrigerator #2 temp is required";
} else {
$refrig2 = test_input($_POST["refrig2"]);
if (!filter_var($refrig2, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax)))) {
$refrig2error = $errormsg;
}
}
if (empty($_POST["refrig3"])) {
$refrig3error = "Refrigerator #3 temp is required";
} else {
$refrig3 = test_input($_POST["refrig3"]);
if (!filter_var($refrig3, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax)))) {
$refrig3error = $errormsg;
}
}
}
Is there a function which I can use to "tidy up" my php code so that I do not have as many lines to debug when things go sideways with the coding?
I think you only have three options here:
Write perfect code so that your code never goes sideways (highly unlikely for any developer :)
Change from an if structure to a switch structure
Evolve your debugging procedure/tools to make debugging less painful in general.
Create an array with the names of the required fields as a key, and an error message as a value. Then loop through this array. Use the keys in the $_POST superglobal to see if it's been set. If it's not set, throw the error message you defined as the value. Something along the lines of:
$required_parameters = array(
"bottomair" => "Maketable bottom air temp is required",
"topair" => "Maketable top air temp is required",
// etc
);
$errorslist = array();
foreach($required_parameters as $key => $error)
{
if(empty($_POST[$key]))
{
$errorslist[] = $error; // append to list
}
else
{
$test = test_input($_POST[$key]);
if (!filter_var($test, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$coldmin, "max_range"=>$coldmax))))
{
$errorslist[] = $errormsg; // <-- I don't know where you define errormsg, though
}
}
}
You can then loop through the $errorslist array as well to display all errors in a list.
I am currently working with validation of US phone numbers. The issue is that code below is always echoing after a valid or invalid input Please enter a valid phone number . My basic logic of my code is that I am checking with the preg_match to see if there is match for a valid number. Example
How can I fix this or is there a better way to validate phone numbers?
Also, Is there away to echo the number formatted like this: (123)456-7890?
PHP:
if (isset($_POST['phone'])) {
if(preg_match('/^(\({1}\d{3}\){1}|\d{3})(\s|-|.)\d{3}(\s|-|.)\d{4}$/',$phone)) {
echo ('<div id="phone_input"><span id="resultval">'.$phone.'</span></div>');
}
else {
echo '<div id="phone_input"><span id="resultval">Please enter a valid phone number</span></div>';
}
}
Try This
<?php
class Validation {
public $default_filters = array(
'phone' => array(
'regex'=>'/^\(?(\d{3})\)?[-\. ]?(\d{3})[-\. ]?(\d{4})$/',
'message' => 'is not a valid US phone number format.'
)
);
public $filter_list = array();
function Validation($filters=false) {
if(is_array($filters)) {
$this->filters = $filters;
} else {
$this->filters = array();
}
}
function validate($filter,$value) {
if(in_array($filter,$this->filters)) {
if(in_array('default_filter',$this->filters[$filter])) {
$f = $this->default_filters[$this->filters[$filter]['default_filter']];
if(in_array('message',$this->filters[$filter])) {
$f['message'] = $this->filters[$filter]['message'];
}
} else {
$f = $this->filters[$filter];
}
} else {
$f = $this->default_filters[$filter];
}
if(!preg_match($f['regex'],$value)) {
$ret = array();
$ret[$filter] = $f['message'];
return $ret;
}
return true;
}
}
//example usage
$validation = new Validation();
echo nl2br(print_r($validation->validate('phone','555-555-1212'),true));
echo nl2br(print_r($validation->validate('phone','(555)-555-1212'),true));
echo nl2br(print_r($validation->validate('phone','555 555 1212'),true));
echo nl2br(print_r($validation->validate('phone','555.555.1212'),true));
echo nl2br(print_r($validation->validate('phone','(555).555.1212'),true));
echo nl2br(print_r($validation->validate('phone','(555)---555.1212'),true));//will not match
?>