Author:
Per Stenebo
Created:
2011-12-16 11:05:29
Modified:
2019-06-01 17:27:41
sv

Regexp

Regular expressions eller Reguljära uttryck

Tutorials: | Regular-expressions.inforegex101.com |

Testa siffror mm med regexp

 webcheatsheet.com

// Regular expression that looks for anything other than numbers
$regexp_num = "/[^0-9]/";

// Regular expression that looks for anything other than numbers and letters
$regexp_num_let = "/[^0-9A-Za-z]/";

// Regular expression that looks for anything other than numbers and dots
$regexp_num_dot = "/[^0-9.]/";

// Regular expression that checks valid date
$regexp_date = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/';

// Regular expression that match a filename like 14_a1c.htm

$pre = '14';
$salt = 'a1c';
$suffix = 'htm';
$regexp_filename = '/^' . $pre . '_' . $salt . '[.]' . $suffix . '$/';

if (preg_match($regexp_num, $input)) {

// Error message if faulty (=true) input
$errors[] = "Fel, endast siffror (0-9) tillåts.";

}

Comments to page Reguljära uttryck