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. Link to comment https://forums.phpfreaks.com/topic/107125-rule-help/ 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> Link to comment https://forums.phpfreaks.com/topic/107125-rule-help/#findComment-549372 Share on other sites More sharing options...
mcmuney Posted May 25, 2008 Author Share Posted May 25, 2008 I think that did it... thanks Link to comment https://forums.phpfreaks.com/topic/107125-rule-help/#findComment-549399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.