Jump to content

Rule Help


mcmuney

Recommended Posts

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

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

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.