Custom Zip and Phone validators

Enter an invalid zip and phone number and click the submit button


PHP/HTML Source:
<?php

require_once("raxan/pdi/autostart.php");

// add custom phone and money validators
$san = Raxan::dataSanitizer();
$san->addDataValidator('Phone', '/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/'); // using regex
$san->addDataValidator('ZipCode','validate_ZipCode'); // using callback
function validate_ZipCode($value){    // validate zip code
    return preg_match('/^(\d{5}-\d{4})|(\d{5})$/',$value);
}

class CustomValidatorPage extends RaxanWebPage {

    protected $frm;

    protected function _config() {
        $this->preserveFormContent = true;
    }

    protected function _init() {
        $this->source('views/custom-validators.html');
    }

    protected function formSubmit($e) {    // event callback
        $msg = array();

        // validate user input
        if (!$this->post->isPhone('phone')) $msg[] ='* Please enter a valid phone number (format: 123-123-1234).';
        if (!$this->post->isZipCode('zipcode')) $msg[] ='* Please enter a valid US Zip code.';

        if (count($msg)>0) {
            $msg = '<strong>'.implode('<br />',$msg).'</strong>';
            $this->flashmsg($msg,'fade','rax-error-pal pad'); // flash msg to browser
        }
    }

}



?>

Plugin Source:

HTML/JavaScript Source (views/custom-validators.html):
<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Custom Validators</title>
    <link href="../raxan/ui/css/master.css" type="text/css" rel="stylesheet" />
    <!--[if lt IE 8]><link rel="stylesheet" href="../raxan/ui/css/master.ie.css" type="text/css"><![endif]-->
    <link href="../raxan/ui/css/default/theme.css" type="text/css" rel="stylesheet" />
    <style type="text/css">
        label {display:block; float:left;width:120px}
    </style>
</head>

<body>
    <div class="container c35">
        <form class="c20" method="post">
            <fieldset>
                <legend>Data Entry</legend>
                <div class="flashmsg"></div>
                <div class="ctrl-group tpm">
                    <label>Phone number:</label><input type="text" name="phone" class="textbox c10" />
                </div>
                <div class="ctrl-group">
                    <label>Zip code:</label><input type="text" name="zipcode" class="textbox c10" />
                </div>
                <hr />
                <input type="submit" value="Submit" xt-bind="click,formSubmit"/>
            </fieldset>
        </form>
    </div>
</body>

</html>

Data Source: