diff --git a/include/class.forms.php b/include/class.forms.php
index 74bb0a64dfcb040dbd5b02fd83a7a8e8de883ccc..bc3ac862f0ee7b733e4f3964dde28ebe78148740 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -907,7 +907,8 @@ class FormField {
                 'placeholder' => __('Valid regular expression'),
                 'configuration' => array('size'=>30),
                 'validators' => function($self, $v) {
-                    if (false === @preg_match($v, ' '))
+                    if (false === @preg_match($v, ' ')
+                        && false === @preg_match("/$v/", ' '))
                         $self->addError(__('Cannot compile this regular expression'));
                 })),
         );
diff --git a/include/class.orm.php b/include/class.orm.php
index 7246dc1b1911a26b83dd0c1de161d21310f0fbc4..a774fc65ea3a51b6ce6d80753f49b6fea7d1dd62 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -1807,7 +1807,7 @@ class SqlCompiler {
         static $operators = array(
             'exact' => 1, 'isnull' => 1,
             'gt' => 1, 'lt' => 1, 'gte' => 1, 'lte' => 1,
-            'contains' => 1, 'like' => 1, 'startswith' => 1, 'endswith' => 1,
+            'contains' => 1, 'like' => 1, 'startswith' => 1, 'endswith' => 1, 'regex' => 1,
             'in' => 1, 'intersect' => 1,
             'hasbit' => 1,
         );
@@ -2204,6 +2204,7 @@ class MySqlCompiler extends SqlCompiler {
         'hasbit' => '%1$s & %2$s != 0',
         'in' => array('self', '__in'),
         'intersect' => array('self', '__find_in_set'),
+        'regex' => array('self', '__regex'),
     );
 
     // Thanks, http://stackoverflow.com/a/3683868
@@ -2265,6 +2266,13 @@ class MySqlCompiler extends SqlCompiler {
         return sprintf('FIND_IN_SET(%s, %s)', $b, $a);
     }
 
+    function __regex($a, $b) {
+        // Strip slashes and options
+        if ($b[0] == '/')
+            $b = preg_replace('`/[^/]*$`', '', substr($b, 1));
+        return sprintf('%s REGEXP %s', $a, $this->input($b));
+    }
+
     function compileJoin($tip, $model, $alias, $info, $extra=false) {
         $constraints = array();
         $join = ' JOIN ';