JM wrote:
Does anyone have a nice email address syntax checking script they'd
like to share? Regular expression-based anyone? TIA.

yes,yes,yes,cheers.



the email regexp passes Richard Lynch's email addr (check the archives :-), have fun (sorry if the line wrapping craps out)...

<?php
/**
 * RegExp.class.php :: class wrapper for regexp stuff
 *
 * @author      Jochem Maas <[EMAIL PROTECTED]>
 * @copyright   Copyright 2003-2004, iamjochem & ard biesheuvel
 *
 * @link http://www.iamjochem.com
 *
 * $Header: /var/cvs/pom_core/php/class/RegExp.class.php,v 1.24 2005/04/12 
11:36:21 jochem Exp $
 */

/* FTL License. Fuck The License */

class RegExp
{
    /* basic */
    const NOT_EMPTY         = '^.{1,}$';
    const DONT_CARE         = '^.*$';

    /* numeric related */
    const UNSIGNED_INT      = '^\d*$';
    const SIGNED_INT        = '^[-+]?\d*$';
    const FLOATING_POINT    = '^[-+]?(\d*\.)?\d+$';
    const FLOAT_GTEQ1       = '^[+]?[1-9]\d*(\.\d+)?$'; // a 'float' greater 
than .999999...
    const PERCENTAGE        = '^100|[0-9]{1,2}$';
    const TIMESTAMP         = ''; // '^\d*$'; // what does the timestamp regexp 
look like??

    const LANG_CHARS        = '^en|nl|fr|de|it|es|vl|us$';
    //const LANG_CHARS        = '^en|nl|fr|de|it|es$';

    const CURRENCY_ID       = '^[a-zA-Z]{3}$';

    /* boolean-ish */
    const BOOLEAN           = '^Y|N$';
    const SEX_NL            = '^M|V$';
    const GENDER            = '^M|F$';

/* contact-type info */
const EMAIL = '^(([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9}))?$';
const EMAIL_REQ = '^(([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9}))$';
const URL = '^(((((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|co\.uk|[a-zA-Z]{2})(\:[0-9]+)?)?(\/($|[a-zA-Z0-9\.\,\;\?\'\\+&%\$#\=~_\-\[\]]+))*)?$';
//const URL = '^((((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|co\.uk|[a-zA-Z]{2})(\:[0-9]+)?(\/($|[a-zA-Z0-9\.\,\;\?\'\\+&%\$#\=~_\-\[\]]+))*)?$';
const PHONE = '^\+?(\d+( *[.-]? *))*$';
const POSTCODE = '^.*$';
const POSTCODE_REQ = '^[0-9a-zA-Z]+([- ][0-9a-zA-Z]+)?$';


    /* page layout - rather specific! */
    const PAGE_LAYOUTS      = '^(tb|bt|lr|rl|null)?$';

    /* e.g. if ( RegExp::match(RegExp::FLOATING_POINT, '16.786541') ) { ... } */
    static public function match($regexp, $value)
    {
        /*
        if (defined("RegExp::{$regexp}")) {
            $regexp = constant("RegExp::{$regexp}");
        }
        */

        return (boolean) preg_match("/$regexp/", $value);
    }
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to