serverside url validation

serverside url validation

rostrost Posts: 26Questions: 9Answers: 1

Description of problem:
I want to validate urls serversideusing code like this:

            Field::inst( 'NameOfField' )
                    ->validator( Validate::url( 
                                  ->message( 'ErrorMessage' )
                ) )

With this I encounter several oddities: in my tests

What do I do wrong?

Or is this behaviour intentional? I read you are using a library (, and they say it validates "relatively 'real-world' " ...

As a workaround I did some experiments with 'pinging' the adresses, which works, but not solid rock - so it would be very nice if someone could help me out.

This question has an accepted answers - jump to answer


  • allanallan Posts: 54,688Questions: 1Answers: 8,553 Site admin
    Answer ✓

    Our PHP libraries use the built in validate filters in PHP (note your link is to a NodeJS package which our PHP libraries do not use).

    What you have above are technically valid URLs which is why they are passing (see this SO thread).

    If you want to be a bit more strict, you might need to use a custom validator with a function similar to one of the answers further down in that thread - there is a is_url function which looks like it will do what you are looking for.


  • rostrost Posts: 26Questions: 9Answers: 1

    Thanks a lot, I will check this :-)

Sign In or Register to comment.