Validating URLs

How many times have you struggled with URL validations? I have struggled a lot. Damn, those stupid regex(s). Well regex as a tech is not stupid, it’s awesome. but when u have a 10,000 regex expressions to choose from? and on the top of that every regex gives different result.

When I faced this challenge, I tested more than 80+ regex expressions, obviously not in a day :P. Then had to settle with a regex which had a least probability of producing -ve results.

Obviously as a programmer, I wanted better alternative. And I stumbled upon PHP filters. Well, it can be used for other things than validation as well such as sanitization, etc.

Why I would like to use filter_var instead of my or anybody else’s regex. Simply because, regex used in filter_Var are well tested and produce far less -ves. Moreover, being a native function, it produces results faster.

As far as my Codeigniter Application is concerned, I have extended the Validation library:

And I am all set *grins*.