vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Need help with URL validation script. (https://vborg.vbsupport.ru/showthread.php?t=181414)

veenuisthebest 06-03-2008 06:33 PM

Need help with URL validation script.
 
Please see the URL validation JavaScript below. You can see it in action here. It works fine but I'd like some changes in it.

1. http:// must be checked for presence. (Currently its invalid format is accepted like tp://)
2. I want the top level domain in the URL to be something valid like only .com, .co.in, .biz, .info, .org, .us, .in etc. should be allowed. (Currently even .xyz is accepted)
3. I don't want to allow inside URL's like http://www.domain.com/sub/test.html. Only domains and sub-domains should be allowed exactly like http://www.domain.com and http://www.home.domain.com (Currently it allows inside URL's)

Code:

<head>
<script type="text/javascript">
<!--
function isValidURL(url){
    var RegExp = /^[\w]+:\/\/(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}

function checkField(){
    var frm = document.frmValidate, error = "";
    if(!isValidURL(frm.url.value)){
        error += "Please enter a valid URL\n";
    }
    if(error != ""){
        alert(error);
        return false;
    }else{
        return true;
    }
}

//-->
</script>
</head>


veenuisthebest 06-05-2008 01:39 PM

still waiting !!

or if someone can help me provide a URL validation script that does not uses onsubmit attribute of form tag.


All times are GMT. The time now is 01:35 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01118 seconds
  • Memory Usage 1,713KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete