You are here: Re: [PHP] Valid email address syntax script? « PHP « IT news, forums, messages
Re: [PHP] Valid email address syntax script?

Posted by Jochem Maas on 10/19/91 11:15

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 <jochem@iamjochem.com>
* @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);
}
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация