Skip to content

Commit

Permalink
Add some basic client side validation for RSS URL input. Needs to be …
Browse files Browse the repository at this point in the history
…augmented with some server-side stuff too (later).
  • Loading branch information
leenookx committed Sep 7, 2009
1 parent 1963003 commit 990dcdd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/views/feeds/new.html.erb
@@ -1,5 +1,19 @@
<%= javascript_include_tag 'validation' %>

<h1>New feed</h1>

<script type="text/javascript">
function verifyFeedURL(s) {
alert(s );
if (! isUrl(s) ) {
alert('Feed URL is invalid.');
return false;
}
else
return true;
}
</script>

<% form_for(@feed) do |f| %>
<%= f.error_messages %>

Expand All @@ -12,8 +26,8 @@
<%= f.text_field :interval %>
</p>
<p>
<%= f.submit 'Create' %>
<%= f.submit 'Create', :onClick => 'return verifyFeedURL( feed_url.value );' %>
</p>
<% end %>
<%= link_to 'Back', feeds_path %>
<%= link_to 'Back', feeds_path %>
Binary file modified db/development.sqlite3
Binary file not shown.
5 changes: 5 additions & 0 deletions public/javascripts/validation.js
@@ -0,0 +1,5 @@
function isUrl(s) {
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(s);
}

0 comments on commit 990dcdd

Please sign in to comment.