Demos » Regular expressions by example

Use this form to test these regular expression examples. Check for each pattern if some kind of value is valid or not. This is jusr a regex example, there is much more you kan do with regular expressions.

All patterns are optimized to use with the PHP function preg_match (note the leading and the trailing slash).

Decimals

This decimal check allows a decimal number with max 5 digits before the "." and 1 or 2 decimals.

/^[1-9]{1}([0-9]{0,5})?\.[0-9]{1,2}$/

Dutch postal code

This postal code is a combination of four numbers and 2 letters (f.e. 1000 AB). With this pattern its allowed to use caps and small caps and a single space or not between numbers and letters.

/^[1-9]{1}[0-9]{3}\s?[a-zA-Z]{2}$/

E-mail address

This example checks real world e-mail addresses, but is limited to the lack of knowledge about the domain names and users. But the pattern takes care about unallowed characters and combinations.

/^[\w-]+(\.[\w-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i

Related PHP functions:

preg_match | preg_replace | preg_match_all | preg_quote

Click here for the PHP script: Regex example patterns