Skip to content

Instantly share code, notes, and snippets.

@jimjam88
Last active December 24, 2015 11:39
Show Gist options
  • Save jimjam88/6792611 to your computer and use it in GitHub Desktop.
Save jimjam88/6792611 to your computer and use it in GitHub Desktop.
<?php
/**
* Regex.php
*
* Simple mapping class for frequently used regular expressions.
*
* @author James Morgan <[email protected]>
*/
final class Regex
{
const TOKEN = '/^ewtX\/.+$/';
const MONEY = '/^[0-9]{1,6}\.[0-9]{2}$/';
const STAKE = '/^[0-9]{1,6}\.[0-9]{1,2}$/';
const BET_PRICE = '/^[0-9]*\.[0-9]*$/';
const DATE = '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/';
const DATETIME = '/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/';
const USERNAME = '/^[A-Z0-9]{6,12}$/';
const ALPHABETIC = '/^[A-Za-z]*$/';
const NUMERIC = '/^[0-9]+$/';
const CHANNELS = '/^I|Z|W|P$/';
const TITLE = '/^Mr|Mrs|Miss|Ms|Dr|Cllr$/';
const IP_ADDRESS = '/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/';
const ODDS_FORMAT = '/^ODDS|DECIMAL|AMERICAN|FRACTION$/';
const BET_RECEIPT = '/^[A-Z]\/[0-9]{8}\/[0-9]{7}$/';
const CURRENCY = '/^GBP|EUR$/';
const CARD_EXPIRY = '/^(0[1-9]|1[0-2])\/[0-9]{2}$/';
const STATUS_FLAG = '/^[A-Z_]*$/';
const EMAIL = '/^[A-Za-z0-9_-]*@[A-Za-z0-9]*\.(com|net|gov|org|edu|biz|info)$/';
const ANYTHING = '/^.+$/';
const GENDER = '/^M|F$/';
const YES_OR_NO = '/^Y|N$/';
const POSTCODE = '/^((((ASCN)|(BBND)|(BIQQ)|(FIQQ)|(PCRN)|(SIQQ)|(STHL)|(TDCU)|(TKCA))[\s]1ZZ)|(GX11[\s]1AA)|(AI-2640)|(PO[\s]BOX[\s][0-9]*)|(GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV]|YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9][0-9]) [0-9][ABD-HJLNP-UW-Z]{2}))$/';
const BLANK = '/^$/';
const ALPHABETIC_AND_BLANKS = '/^[A-Za-z ]*$/';
const ALPHABETIC_OR_EMPTY = '/^[A-Za-z]*|$/';
const NUMERIC_OR_EMPTY = '/^[0-9]*|$/';
const ANYTHING_OR_EMPTY = '/^.+|$/';
const UPPERCASE_ALPHABETIC = '/^[A-Z]*$/';
const PASSPORT_REGEX = '/^[A-Z0-9<]{9}[0-9][A-Z][A-Z<]{2}[0-9]{2}[01][0-9][0-3][0-9]{2}[MF<][0-9]{2}[01][0-9][0-3][0-9]{2}[A-Z0-9<]{14}[0-9<][0-9]$/i';
/**
* Escape a string.
*
* @param string $str
* @return string
*/
public static function escape($str)
{
return '/^' . preg_quote($str, '/') . '$/';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment