Posts in:
regular expression

Directory Listing from a Path

$path = dirname(__FILE__); $listing = array_filter(scandir($path), function($var) { // remove special directories ‘.’ and ‘..’ from listing if( preg_match(‘/^[\.]{1,2}$/’, $var) ) { return FALSE; } // remove files from listing if( !is_dir($var) ) { return FALSE; } return TRUE; }); This is a little snippet of code I’ve been using a lot recently. This function [...]

Validate a Credit Card Number

This code snippet is a regular expression which checks or validates a credit card number.
The Expression: ^([0-9]{4})[\-|\s]*([0-9]{4})[\-|\s]*([0-9]{4})[\-|\s]*([0-9]{2,4})$

Validate a Phone Number

This code snippet is a regular expression which checks or validates a phone number.
The Expression: ^[\+]?([0-9]?)[\(|\s|\-|\.]?([0-9]{3})[\)|\s|\-|\.]*([0-9]{3})[\s|\-|\.]*([0-9]{4})$