mcmuney Posted May 24, 2008 Share Posted May 24, 2008 I'm using the following to validate that a valid URL has been entered, BUT when I enter a valid url that starts with a number, it doesn't accept it as valid. I'd appreciate someone modifying the code to accept urls that start with a number (this is not my area): <script type="text/javascript"> function validate_url(o,e){ var patu = /^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+(\.[a-zA-Z]{2,4}){1,2}(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/i; var patd = /^[a-zA-Z][a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+$/i; R=$("#frm1url").val(); if(R && R.length>0 && R.match(patu)!=null){ return true; }else if(R && R.length>0 && R.match(patd)!=null){ return true; }else{ alert("Invalid url entered"); return false; } } </script> Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 25, 2008 Share Posted May 25, 2008 Try this: <script type="text/javascript"> function validate_url(o,e){ var patu = /^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+(\.[a-zA-Z]{2,4}){1,2}(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/i; var patd = /^[a-zA-Z0-9][a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+$/i; R=$("#frm1url").val(); if(R && R.length>0 && R.match(patu)!=null){ return true; }else if(R && R.length>0 && R.match(patd)!=null){ return true; }else{ alert("Invalid url entered"); return false; } } </script> Quote Link to comment Share on other sites More sharing options...
mcmuney Posted May 25, 2008 Author Share Posted May 25, 2008 I think that did it... thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.