Forums

Removing the need for http in URL validation

andypooz 09 Feb, 2012
I've been reading other posts related to validation and one by Bob referred to the URL validation, as i wanted to remove the need for putting 'http://' at the start of URL ('Normal' people don't understand http - I barely do).

I found the file administrator/components/com_chronoforms/form_actions/auto_serverside_validation/auto_serverside_validation.php

Where I found:

return preg_match('/^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&%\$#\=~])*$/i', $form->data[$str]);


I'm afraid my regular expression skills aren't very good. I tried changing it to:

return preg_match('/^[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&%\$#\=~])*$/i', $form->data[$str]);


and something interesting happened- nothing at all. It was still insisting on entering http:// and it still passed validation when i did put it in.

Any ideas? I'm not sure I've edited the right file, as I was really expecting to see a server error, but nothing at all. Any regexp people, what should my new preg_match look like- have I edited it correctly? And why has it made no difference at all- is the validation contained in another file- I am wondering why it's in the admin files, but there seems to equivalent in the front end files.
Cheers
Andy
GreyHead 09 Feb, 2012
Hi andypooz,

There are some examples and links to other sources here

Bob
This topic is locked and no more replies can be posted.