Username:   Password:  

Verify email address with Javascript

function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return true;
	}
	return false;
}

Verifies, if input is a valid email address with Javascript by using regular expressions

Tags

regex email verify verification address JS Javascript

Test filename in PHP

/**
 * Tests, if given filename is valid
 *
 * @param string $filename
 * @return bool
 */
public static function isValidFilename($filename) {
	return (bool) preg_match('/^[a-z0-9_ ]{1,30}.[a-z]{1,3}$/i', $filename);
}

Tests, if a given filename is valid.

Tags

PHP files filename test verify

Test if telephone number belongs to a cellphone

function isCellphoneNumber($tel) {
	// Remove all non relevant characters
	$tel = preg_replace("/[^0-9\+]/", '', $tel);
 
	$number = '';
	$countryCode = 0;
 
	if (preg_match("/^\+\d{2}/", $tel)) {
		// Number with country code with trailing +
		$countryCode = substr($tel, 1, 2);
		$number = substr($tel, 3, strlen($tel) - 3);
		$number = "00".$countryCode.$number;
	} elseif (preg_match("/^00/", $tel)) {
		// Country code present with trailing 00
		$landesVorwahl = substr($tel, 2, 2);
		$number = substr($tel, 4, strlen($tel) - 2);
		$number = "00".$landesVorwahl.$number;
	}
 
	switch ((int) $countryCode) {
		default:
		case 49: // Germany
			$netzvorwahlen = array(
					'0151', '0160',
					'0170',	'0171',	'0175',	'0151',
					'01520', '0162', '0172',	'0173',
					'0174',	'0152',	'0157',	'01570',
					'01577', '0163', '0177',	'0178',
					'0155',	'0159',	'0176', '0179'
				);
			break;
 
		case 43: // Austria
			$netzvorwahlen = array(
					'0664',
					'0676',
					'0650',
					'0699'
				);
			break;
 
		case 41: // Swiss
			$netzvorwahlen = array(
					'079',
					'076',
					'078',
					'077'
				);
			break;
 
		case 29: // Spanien
			$netzvorwahlen = array('6'); // In ESP beginnen alle Handynummern mit einer 6
			break;
	}
 
	foreach ($netzvorwahlen as $vorwahl)
	{
		$vorwahl = preg_replace("/^0/", '', $vorwahl);
 
		if (preg_match("/^00${landesVorwahl}${vorwahl}/", $nummer))
		{
			$tel = $nummer;
 
			return true;
		}
	}
 
	return false;
}
 

This function only supports cellphone numbers for the german speaking part of europe (swiss, germany, austria).

Tags

cellphone number php verify