summaryrefslogtreecommitdiffstats
path: root/assets
diff options
context:
space:
mode:
authorTeddy Wing2013-11-10 06:33:01 -0500
committerTeddy Wing2013-11-10 06:33:01 -0500
commit70440be316d8ea96ddd4583cad9219620c4ba2ac (patch)
tree06481f72d761ba6d787ab9738248ecd4398d08cb /assets
parent7aed65d5c8cc01fc554f608d5fed2a16836ae978 (diff)
downloadclip-play-70440be316d8ea96ddd4583cad9219620c4ba2ac.tar.bz2
Validate that the input is a URL
Use a JavaScript version of John Gruber's URL validator to make sure that what is inputted into the box is in fact a URL. TODO: there is a BUG in that it accepts URL without an http:// prefix and we require that to be there.
Diffstat (limited to 'assets')
-rw-r--r--assets/js/views/sample-add-view.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/assets/js/views/sample-add-view.js b/assets/js/views/sample-add-view.js
index 7080c84..2d3372e 100644
--- a/assets/js/views/sample-add-view.js
+++ b/assets/js/views/sample-add-view.js
@@ -1,4 +1,9 @@
ClipPlay.Views.SampleAddView = Marionette.View.extend({
+ // Copied from
+ // http://daringfireball.net/2010/07/improved_regex_for_matching_urls
+ // http://stackoverflow.com/questions/6927719/url-regex-does-not-work-in-javascript
+ url_matcher: /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i,
+
events: {
'click .js-create-sample': 'on_sample_add'
},
@@ -19,12 +24,14 @@ ClipPlay.Views.SampleAddView = Marionette.View.extend({
},
on_sample_add: function() {
- if (this.$input.val()) {
+ var input_value = this.$input.val();
+ if (input_value
+ && this.url_matcher.test(input_value)) {
this.add_sample_to_collection();
-
- this.clear_input();
}
+ this.clear_input();
+
return false;
}
}); \ No newline at end of file