From b1c1175c67bc22102a3a8d31ea6b7ec1c56a6a56 Mon Sep 17 00:00:00 2001
From: root <root@lagshot.com>
Date: Thu, 2 Dec 2010 00:54:35 +0300
Subject: [PATCH] javascript validations for username

---
 app/views/invitations/edit.html.haml  | 16 ++++++++++++++++
 app/views/registrations/new.html.haml | 16 ++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/app/views/invitations/edit.html.haml b/app/views/invitations/edit.html.haml
index 1eac967f66..306d4fd182 100644
--- a/app/views/invitations/edit.html.haml
+++ b/app/views/invitations/edit.html.haml
@@ -1,3 +1,19 @@
+ :javascript
+  $(function() {
+    var Validation = {
+      username: {
+        characters: /^(|[A-Za-z0-9_]{0,32})$/,
+        length: [6, 32]
+      }
+    };
+
+    $("#user_username").keypress(function(evt) {
+      if(!Validation.username.characters.test(this.value + String.fromCharCode($
+        evt.preventDefault();
+      }
+    });
+  });
+
 = form_for(resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :put }) do |f|
   %p
     = f.label :username
diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml
index a8f54e153b..cfe6e2dc2f 100644
--- a/app/views/registrations/new.html.haml
+++ b/app/views/registrations/new.html.haml
@@ -1,3 +1,19 @@
+ :javascript
+  $(function() {
+    var Validation = {
+      username: {
+        characters: /^(|[A-Za-z0-9_]{0,32})$/,
+        length: [6, 32]
+      }
+    };
+
+    $("#user_username").keypress(function(evt) {
+      if(!Validation.username.characters.test(this.value + String.fromCharCode($
+        evt.preventDefault();
+      }
+    });
+  });
+
 .span-12.prepend-6.last
   .floating
     %h3
-- 
GitLab