diff --git a/clientside_validation.admin.inc b/clientside_validation.admin.inc
index 94d8d4d..f6e814f 100644
--- a/clientside_validation.admin.inc
+++ b/clientside_validation.admin.inc
@@ -363,8 +363,32 @@ function clientside_validation_admin_settings() {
       ),
     ),
   );
+
+   //XRegExp settings
+  $form['clientside_validation_xregxp'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+    '#title' => t('XRegExp for Pattern matching'),
+    '#description' =>t('Javascript doesn\'t support regular expressions for pattern matching the way PHP does. With the XRegExp library most PHP expressions(pregex) become also available in Javascript. So you might want to use that instead of AJAX calls.<br>
+     You can Download the library(+ plugins you wish) from !xregexplink and put it in sites/all/libraries/xregexp (create the directory).',
+      array(
+        '!xregexplink' =>
+        l('http://xregexp.com/', 'http://xregexp.com/')
+      )),
+  );
+
+  $form['clientside_validation_xregxp']['clientside_validation_usexregxp'] = array(
+    '#prefix' => '<br>',
+    '#title' => t('Use XRegExp'),
+    '#description' => t('Check to use XRegExp for PCRE.'),
+    '#type' => 'checkbox',
+    '#default_value' => variable_get('clientside_validation_usexregxp', 0),
+  );
+
   $form['#submit'] = array('clientside_validation_admin_settings_submit');
   $form = system_settings_form($form);
+  
   return $form;
 }
 
diff --git a/clientside_validation.js b/clientside_validation.js
index a29931e..9940e17 100644
--- a/clientside_validation.js
+++ b/clientside_validation.js
@@ -520,6 +520,68 @@
   }
 
   Drupal.clientsideValidation.prototype.addExtraRules = function(){
+    var self = this;
+    var ajaxPCREfn = function(value, element, param) {
+      var result = false;
+      jQuery.ajax({
+        'url': Drupal.settings.basePath + 'clientside_validation/ajax',
+        'type': "POST",
+        'data': {
+          'value': value,
+          'param': param
+        },
+        'dataType': 'json',
+        'async': false,
+        'success': function(res){
+          result = res;
+        }
+      });
+      if (result['result'] === false) {
+        if (result['message'].length) {
+          jQuery.extend(jQuery.validator.messages, {
+            "regexMatchPCRE": result['message']
+          });
+        }
+      }
+      return result['result'];
+    };
+
+    var xregexPCREfn = function(value, element, param) {
+      if(window.XRegExp && XRegExp.version ){
+        var result = true;
+        for(var i = 0; i < param['expressions'].length; i++){
+          var reg = param['expressions'][i];
+            reg = reg + 'g';
+          var delim = reg.lastIndexOf(reg[0]);
+          var mod = reg.substr(delim + 1);
+          reg = reg.substring(1, delim );
+            console.info(reg + ' ' + mod);
+          if(! XRegExp(reg,mod).test(value)){
+            result = false; 
+             console.info('error at' + reg + ' ' + mod);
+            if (param['messages'][i].length) {
+	      jQuery.extend(jQuery.validator.messages, {
+		"regexMatchPCRE": param['messages'][i]
+	      });
+	    }
+          }else{
+             console.info('verified' + reg + ' ' + mod);  
+          }
+
+        }        
+        return result;
+      }
+      //no lib head for ajax
+      return ajaxPCREfn(value, element,param);
+    };
+
+    jQuery.validator.addMethod("regexMatchXREGPCRE",xregexPCREfn, jQuery.format('The value does not match the expected format.'));
+    jQuery.validator.addMethod("regexMatchPHPPCRE",ajaxPCREfn, jQuery.format('The value does not match the expected format.'));
+    if(self.data.general.usexregxp){
+      jQuery.validator.addMethod("regexMatchPCRE",xregexPCREfn, jQuery.format('The value does not match the expected format.'));
+    }else{
+      jQuery.validator.addMethod("regexMatchPCRE",ajaxPCREfn, jQuery.format('The value does not match the expected format.'));
+    }
 
     jQuery.validator.addMethod("numberDE", function(value, element) {
       return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
@@ -568,31 +630,6 @@
       return true;
     });
 
-    jQuery.validator.addMethod("regexMatchPCRE", function(value, element, param) {
-      var result = false;
-      jQuery.ajax({
-        'url': Drupal.settings.basePath + 'clientside_validation/ajax',
-        'type': "POST",
-        'data': {
-          'value': value,
-          'param': param
-        },
-        'dataType': 'json',
-        'async': false,
-        'success': function(res){
-          result = res;
-        }
-      });
-      if (result['result'] === false) {
-        if (result['message'].length) {
-          jQuery.extend(jQuery.validator.messages, {
-            "regexMatchPCRE": result['message']
-          });
-        }
-      }
-      return result['result'];
-    }, jQuery.format('The value does not match the expected format.'));
-
     // Unique values
     jQuery.validator.addMethod("notEqualTo", function(value, element, param) {
       var target = $(param).unbind(".validate-notEqualTo").bind("blur.validate-notEqualTo", function() {
diff --git a/clientside_validation.module b/clientside_validation.module
index 653930f..72d650f 100644
--- a/clientside_validation.module
+++ b/clientside_validation.module
@@ -126,6 +126,44 @@ function clientside_validation_form_alter(&$form, &$form_state, $form_id) {
   }
 }
 
+/* adds xregexp and optional unicode js lib
+ */
+function clientside_validation_add_xregexp(){
+  $xregxppath = 'sites/all/libraries/xregexp';
+  if(!is_dir($xregxppath)){
+    $xregxppath = drupal_get_path('module', 'clientside_validation') . "/xregexp";
+    if(!is_dir($xregxppath)){
+      return;
+    }
+  }
+
+  $regexlib ="$xregxppath" . '/xregexp-min.js';
+  if(!is_file($regexlib)){
+    $regexlib ="$xregxppath" . '/xregexp.js';
+    if(!is_file($regexlib)){
+      return;
+    }
+  }
+
+  drupal_add_js($regexlib); 
+  if(!is_file("$xregxppath" . "/xregexp-unicode-base.js")){
+    return;
+  }
+
+  drupal_add_js("$xregxppath" . "/xregexp-unicode-base.js");
+  if(is_file("$xregxppath" . "/xregexp-unicode-categories.js")){
+    drupal_add_js("$xregxppath" . "/xregexp-unicode-categories.js");
+  }
+
+  if(is_file("$xregxppath" . "/xregexp-unicode-scripts.js")){
+    drupal_add_js("$xregxppath" . "/xregexp-unicode-scripts.js");
+  }
+
+  if(is_file("$xregxppath" . "xregexp-unicode-blocks.js")){
+    drupal_add_js("$xregxppath" . "/xregexp-unicode-blocks.js");
+  }
+}
+
 /**
  * Webform.
  */
@@ -144,6 +182,12 @@ function clientside_validation_webform_after_build(&$form, &$form_state) {
     else {
       drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/jquery-validate/jquery.validate.min.js');
     }
+
+    //add xregxp if choosen.  
+    if(variable_get('clientside_validation_usexregxp',0) != 0){
+      clientside_validation_add_xregexp();
+    }
+
     //add our js file to the footer to support vertical_tabs
     drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/clientside_validation.js', array('scope' => 'footer', 'weight' => 20));
     drupal_add_js($settings, 'setting');
@@ -231,6 +275,12 @@ function clientside_validation_form_after_build(&$form, &$form_state) {
     else {
       drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/jquery-validate/jquery.validate.min.js');
     }
+
+    //add xregxp if choosen.  
+    if(variable_get('clientside_validation_usexregxp',0) != 0){
+      clientside_validation_add_xregexp();
+    }
+
     //add our js file to the footer to support vertical_tabs
     drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/clientside_validation.js', array('scope' => 'footer', 'weight' => 20));
     drupal_add_js($settings, 'setting');
@@ -305,6 +355,7 @@ function _clientside_validation_add_general_settings(&$settings, $form_id) {
     "validateOnSubmit" => variable_get('clientside_validation_validate_onsubmit', 1),
     "errorElement" => variable_get('clientside_validation_error_element', 'label'),
     "showMessages" => variable_get('clientside_validation_show_messages', 0),
+    "usexregxp" => variable_get('clientside_validation_usexregxp',0),
   );
 }
 
