Method that checks the field value

Hi All,

I have the following method that checks the fields value:

if (abnormalchat != null && abnormalchat != -1|| abnormalchat != 0 || abnormalchat != 1 || abnormalchat != 2 || abnormalchat != 3 || abnormalchat != 8 || abnormalchat != 9  )
{
message += ' abnormalchat value should be -1 , 0 , 1 ,  2 , 3 , 8 or 9  . \n';
}

 if(message.equals("")) 
{
message1 += 'All constratints ok!!..\n';
var ALERT2 =  plugins.dialogs.showInfoDialog( 'Result', message1, 'OK'); 
} 
else 

{
var ALERT1 =  plugins.dialogs.showInfoDialog( 'Result', message, 'OK');
}

the problem is that if I have null value or any of the above values into the field I still get message:

message += ' abnormalchat value should be -1 , 0 , 1 ,  2 , 3 , 8 or 9  . ' .

What is the problem here :shock:
By the way I am using combobox if that makes any difference

Thanks for any help

Abrahim

Do this:

if (!abnormalchat || (abnormalchat < 4 && abnormalchat != 8 && abnormalchat != 9) ) 
{ 
message += ' abnormalchat value should be -1 , 0 , 1 ,  2 , 3 , 8 or 9  . \n'; 
} 

 if(!message) 
{ 
message1 += 'All constratints ok!!..\n'; 
var ALERT2 =  plugins.dialogs.showInfoDialog( 'Result', message1, 'OK'); 
} 
else 

{ 
var ALERT1 =  plugins.dialogs.showInfoDialog( 'Result', message, 'OK'); 
}

You evaluation is wrong

Marcel,

Using:

var message = '';
var message1 = '';

if (!abnormalchat || (abnormalchat < 4 && abnormalchat != 8 && abnormalchat != 9) ) 
{ 
message += ' abnormalchat value should be -1 , 0 , 1 ,  2 , 3 , 8 or 9  . \n'; 
} 

 if(!message) 
{ 
message1 += 'All constraints ok!!..\n'; 
var ALERT2 =  plugins.dialogs.showInfoDialog( 'Result', message1, 'OK'); 
} 
else 

{ 
var ALERT1 =  plugins.dialogs.showInfoDialog( 'Result', message, 'OK'); 
}

Now, if we input 12345 or 11111 in abnormalchat field, then
informs us :
'All constraints ok!!..

But we know that 12345 or 11111 are not correct value.

Abrahim

huh, but ‘12345’ is not smaller then 3, not 8 and not 9 so…

When you want to check each int you have to loop through it…

Ok,

How about “0”?

If I input 0, then:

message will popup:

abnormalchat value should be -1 , 0 , 1 , 2 , 3 , 8 or 9

I chenged the if to:

if (!abnormalchat && (abnormalchat != -1 || abnormalchat != 0 || abnormalchat != 1 || abnormalchat != 2  || abnormalchat != 4 || abnormalchat != 8 || abnormalchat != 9) ) 
{ 
message += ' abnormalchat value should be -1 , 0 , 1 ,  2 , 3 , 8 or 9  . \n'; 
}

but message will popup:

abnormalchat value should be -1 , 0 , 1 , 2 , 3 , 8 or 9

Abrahim

Well, there I made a mistake, did not interpret what you wanted but what you did. In that case you can do the following:

if (!abnormalchat || abnormalchat < -1 || (abnormalchat > 3 && abnormalchat != 8 && abnormalchat != 9) )

Marcel,

using 0 as value still message popup:

var message = ''; 
var message1 = ''; 

if (!abnormalchat || abnormalchat < -1 || (abnormalchat > 3 && abnormalchat != 8 && abnormalchat != 9) )
{ 
message += ' abnormalchat value should be -1 , 0 , 1 ,  2 , 3 , 8 or 9  . \n'; 
} 

 if(!message) 
{ 
message1 += 'All constraints ok!!..\n'; 
var ALERT2 =  plugins.dialogs.showInfoDialog( 'Result', message1, 'OK'); 
} 
else 

{ 
var ALERT1 =  plugins.dialogs.showInfoDialog( 'Result', message, 'OK'); 
}

abnormalchat value should be -1 , 0 , 1 , 2 , 3 , 8 or 9

:shock:

Abrahim

Ah, yes that is correct. replace !abnormalchat with abnormalchat == null

Thanks Marcel!

That was the fix :D

Regards,

Abrahim

Great :) Have fun…