Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <web-client> master : admin config - added custom email validation
  • From: Ladislav Slezak <lslezak@xxxxxxxxxx>
  • Date: Thu, 24 Sep 2009 17:09:36 +0200
  • Message-id: <E1Mqpzy-0004kJ-Aw@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 36c851d2bd8294e085292b973c03346c6be23c9e
Author: Ladislav Slezak <lslezak@xxxxxxxxxx>
Date: Thu Sep 24 17:09:36 2009 +0200

admin config - added custom email validation

- the input values is actually a list of email addresses separated by comma
so a custom validation is needed
- the validation allows to enter just user name (without @domain.com)
for local user forwarding
---
.../app/views/administrator/index.html.erb | 41 ++++++++++++++------
1 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/plugins/administrator/app/views/administrator/index.html.erb
b/plugins/administrator/app/views/administrator/index.html.erb
index 439fabc..6d753a3 100644
--- a/plugins/administrator/app/views/administrator/index.html.erb
+++ b/plugins/administrator/app/views/administrator/index.html.erb
@@ -7,17 +7,34 @@
label.error { float: none; color: red; padding-left: .5em; vertical-align:
top; }
</style>

- <% javascript_tag do -%>
- $(document).ready(function(){
- $("#adminForm").validate({
- rules: {
- "administrator[confirm_password]": {
- equalTo: "#administrator_password"
- }
- }
+ <script type="text/javascript">
+ // define custom validation function
+ // alias is actually a list of email aliases
+ jQuery.validator.addMethod("emails", function(value, element) {
+ if (this.optional(element)) return true;
+
+ var emails = value.split(",");
+
+ for(i=0; i < emails.length; i++){
+ var email = $.trim(emails[i]);
+
+ // add a dummy domain if it's missing
+ // user name without a domain is valid as well (local alias)
+ if (email.search(/@/) < 0) email += "@example.com";
+
+ // TODO FIXME: use jQuery call here, remove the copy pasted regex
+ // unfortunately jQuery.validator.methods.email(email, element)
doesn't work :-(
+ if
(!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email))
+ return false;
+ }
+
+ return true;
+ }, "Please specify correct email address.");
+
+ $(document).ready(function(){
+ $("#adminForm").validate()
});
- });
- <% end %>
+ </script>

<% end %>

@@ -35,12 +52,12 @@
</tr>
<tr class="bg">
<td class="first"><strong><%=_("Confirm Password")%></strong></td>
- <td class="last"><%= f.password_field :confirm_password, :disabled =>
disabled %></td>
+ <td class="last"><%= f.password_field :confirm_password, :disabled =>
disabled, :equalTo => "#administrator_password" %></td>
<td><%= f.submit _("Save"), :name => "save_password", :disabled =>
disabled %></td>
</tr>
<tr class="bg">
<td class="first"><strong><%=_("Forward mail to")%></strong></td>
- <td class="last"><%= f.text_field :aliases, :disabled => disabled,
:class => "email" %></td>
+ <td class="last"><%= f.text_field :aliases, :disabled => disabled,
:class => "emails" %></td>
<td><%= f.submit _("Save"), :name => "save_aliases", :disabled =>
disabled %></td>
</tr>
<tr>
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages