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'],
Posted by
chevrons in
Yii2
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
}
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.