August 29 2016

Yii2 number compare validation rules

Tagged Under :

Yii
In Yii2 compare two numbers attributes in operator function. you will found that it not working properly. This is because the wrongly “type” in compare validation rules.

You may need to set the type to number as below:
'type' => 'number'
Example:
['min_price', 'compare', 'compareAttribute' => 'max_price', 'operator' => '<', 'type' => 'number'],

August 29 2016

Jquery find the specific Id if exists

Tagged Under :

javascript
If want to check the specific Id already exists inside the site. you may using “length” to do it.

For Example:
if( $('#selector').length) {
     // it exists
}
if the length more then 0, that’s mean the following Id already exists inside the site.

if you are using class to check
if( $('.selector').length) {
     // it exists
}

August 29 2016

check if a string is JSON in Javascript

Tagged Under :

javascript
In javascript it don’t have function to check if the string is JSON. So we may need to write a function to check the string if is JSON.

The below function is to check the string and it will return true if the string is JSON else it will return false.