The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jquery url validation / Allow only specific urls
#1
Question 
Hi
how can i allow only links from specific urls?

"https://www.youtube.com/watch?v="

so user can only add youtube video urls ? Huh

jquery validation plugin have the rule "url"
but thats not what i need..

any ideas for me ?
  Reply
#2
(02-19-2019, 10:25 PM)Vtins Wrote: Hi
how can i allow only links from specific urls?

"https://www.youtube.com/watch?v="

so user can only add youtube video urls ? Huh

jquery validation plugin have the rule "url"
but thats not what i need..

any ideas for me ?

What if instead of having them give the whole link, they just give the code...  Like if the video is https://www.youtube.com/watch?v=0sr1Xeocuuc have them just submit 0sr1Xeocuuc and you do the rest when you echo it back out?
  Reply
#3
i have a url form input where users cann add youtube videos.

if users try to add this url i need to echo a validation error
"https://youtube.com/channelname"

echo a validation error too on this example
"https://otherdomain.com"



i need to allow only values thats contain youtube video urls like this
"https://www.youtube.com/watch?v="



But users needs to type the fully youtube url ... not only the video id
  Reply
#4
(02-19-2019, 10:38 PM)Vtins Wrote: i have a url form input where users cann add youtube videos.

if users try to add this url i need to echo a validation error
"https://youtube.com/channelname"

echo a validation error too on this example
"https://otherdomain.com"



i need to allow only values thats contain youtube video urls like this
"https://www.youtube.com/watch?v="



But users needs to type the fully youtube url ... not only the video id

I made a quick demo for you. You can save it in users/whatever.php and then run that file.  https://pastebin.com/01x5GZuT

Essentially what you need to do is give your form an id of "myform"  and your url input an id of "url"  Then add this javascript to the bottom of the page.

Code:
<script type="text/javascript">
$( document ).ready(function() {
   $('#myform').submit(function (e) {
           var url = $("#url").val(); //get the url from the input by the id url
           console.log(url);
           var lowercase = url.toLowerCase(); //temporarily convert to lowercase to avoid issues
           if(lowercase.startsWith('https://www.youtube.com/watch?v=') == false && lowercase.startsWith('https://m.youtube.com/watch?v=') == false) {
               e.preventDefault();
               alert("Invalid youtube url.  Must be https://www.youtube.com/watch?v=xxxxxxx.");
           }
   })

});
</script>

Again, there's a full demo if you want to see it in action.
  Reply
#5
I'm also collecting YouTubes but I'm doing it similarly to how Mudmin suggests above - only accepting the video id rather than trying to navigate the numerous forms of a YT url (there's also https://youtu.be/xyzxyzxyz from the 'share' section).

You could create a YT search facility, here's mine: https://youtu.be/gxcz83OFB1g Note line 79 is one of many options.
  Reply
#6
(02-20-2019, 10:35 AM)astropos Wrote: I'm also collecting YouTubes but I'm doing it similarly to how Mudmin suggests above - only accepting the video id rather than trying to navigate the numerous forms of a YT url (there's also https://youtu.be/xyzxyzxyz from the 'share' section).

You could create a YT search facility, here's mine: https://youtu.be/gxcz83OFB1g Note line 79 is one of many options.

ah yeah. I forgot about youtu.be 
Smile
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)