Jump to content

url validation


jimfog

Recommended Posts

So far I've used php filter for validating the url. I just noticed though that URLs like http://kkk pass validation...something I do not want.

Do I have to resort to regular expression? And if yes...can you give me a help on that?

Link to comment
Share on other sites

I found a regular expression to use.It is too long to show it...I do not think it matters anyway though.

I have 1 question though. What is the reason for using quote inside the pattern...here is an example:

da-f]{2})|[!$&'()*+

PHP manual does not list quote as being a meta-character.

Link to comment
Share on other sites

Ok, I understood. I have never heard/seen though of an URL having a quote.

Have you?

And another thing. This is the pattern I found to use for the regular expression:https://raw.github.com/jzaefferer/jquery-validation/master/src/additional/url2.js

After playing a while with it I found that it is very cumbersome to wotk with such code...when errors appear they are difficult to be found

Maybe I should use the validate filter at all.

 

WHat is your opinion?

Link to comment
Share on other sites

According to RFC 3986, which defines URI syntax, a single quote is a reserved character for various parts of the URI including the userinfo segment and is also reserved for future IP address syntax.

 

http://tools.ietf.org/html/rfc3986

 

The regular expression you showed is pretty close to the URL filter, it is supposed to validate any valid URL. Obviously the rules are not trivial, which is why it is complex. That regular expression also allows an optional TLD like the URL you showed, so if you're going to use that anyway then you might as well just use the built-in validator.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...