Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 url validation without http,https

I have used url validation code in my model,but it gives me error. I just validate if user only put like google.com or yahoo.com not http,www required. How i can do this.

 [['thankyou_page_url','confirmation_page_url'],'url'],
like image 869
Muhammad Shahzad Avatar asked Feb 16 '15 04:02

Muhammad Shahzad


1 Answers

I'm not able to test it right now. But I think you need to add the defaultScheme option. The default value of defaultScheme is null which means there must be a valid scheme in the URL.

If you change it to

[['thankyou_page_url','confirmation_page_url'],'url', 'defaultScheme' => 'http'],

the http:// part will automatically be added if you don't supply anything in the input. I think if you set the defaultScheme to an empty string it will also allow URL's without a scheme. So maybe this works:

[['thankyou_page_url','confirmation_page_url'],'url', 'defaultScheme' => ''],
like image 177
Jap Mul Avatar answered Oct 04 '22 22:10

Jap Mul