I added below script to validate url in my form field. It shows valid url.Even if i use magento default class validate-url It won't show error.


  echo "invalid url";
   echo "valid url";

How to fix this issue.

  • I am a bit confused as to what you are trying to achieve here. The url is valid from what I can see so both the validation.js and your regex will return that it is valid. What is the problem that you are looking to solve? – David Manners Jun 20 '14 at 7:00
  • this is www.google.co invalid url. but it shows valid url.Is there any possibilities in the above method. – saravanavelu Jun 20 '14 at 7:03

The regex you have posted does not really do what you think it does. If you post this into a regex tool like:

  1. http://www.regexr.com/
  2. http://regex101.com/

Then you will be able to debug your regex, but basically what you have is a match for either http:// or www. so in your case www.google.co is perfectly valid.

Magento's js/prototype/validation.js offers two different url validation options.

  1. validate-url - which requires either http:// https:// or ftp://
  2. validate-clean-url - which will work without the protocol,

So to make your regex work with the protocol you can use the following:


But be warned that this will also match http://a which I guess you do not want it to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.