Jump to content

Little hlp plz


Dathremar

Recommended Posts

Hello, I really can't figure out this (cuz I am really not good with javascript) :

function valid_web(web)

{

var filter  = /([a-zA-Z0-9_\.\-])+(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

uslov = ((web.substr(0,4) == "www.") || (web.substr(0,7) == "http://"));

return (uslov && filter.test(web));

}

This is function for validatin if it is a web/link ok i get that, but when i input a name like this one : http://path/to/file/Upatstvo voip mk v1 5.doc - it returns false. If I just delete the last blank spot between the 1 and 5 it returns true. Because this doesn't make any sense to me, could be some1 kind enough and knows java script to explain to me whats happening in the function. Or at least explain the filter variable (thats what i dont understand meaning what all those signs mean, which of them are the filter and which are the concatenation or something marks).

Thx

Link to comment
https://forums.phpfreaks.com/topic/112899-little-hlp-plz/
Share on other sites

I'm not an expert but it looks to me that your first line is a filter that only allows certain characters to be used. Spaces are not included in web links. Could you change the path to use underscores instead of spaces? That would solve your problem.

 

ie; http://path/to/file/Upatstvo_voip_mk_v1_5.doc

Link to comment
https://forums.phpfreaks.com/topic/112899-little-hlp-plz/#findComment-579897
Share on other sites

Yeah that's true. But the same variable here it is used for the link to the file and for the file name so if i change that then the link will not work. Imo it is stupid to upload files without changing their name or at least adopt them for further usage, but i am not the creator of this program :( So I can't change that.

About the blank spaces. Strange thing is that only the last blank space is making a problem. If i remove only the last one then the name is valid.

Thats why I wanted some1 to explain the filter to me in more details.

 

ie. This part a-zA-Z0-9 i know it means it can include a-z and A-Z letters number 0-9,but i dont understand _\.\-])+(( and \-])+\.)+( in between this info.

 

 

Link to comment
https://forums.phpfreaks.com/topic/112899-little-hlp-plz/#findComment-579901
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.