Question

When I check my input from a text box, I pass it into a loop to check individual characters.

I'm a little uncertain as to why this is happening, but when I input a "/", the function reads it as false?

 // Checks the Password contains the correct input 
 for (i = 0; i < passwordLength; i++)
 {
     v = Convert.ToInt32(passwordArray[i]);
     // (not 0-9 or not A-Z or not a-z) 
     // "/"(converted to 47) reads as (true)+(true)+(false) = false
     if ((v < 48 || v > 57) && (v < 65 || v > 90) && (v < 97 || v > 122))
     {
         e = 2;
     }
 }
Was it helpful?

Solution

try this in your if condition

if (!(v >= 48 && v <= 57) && !(v >= 65 && v <= 90) && !(v >= 97 && v <= 122))

OTHER TIPS

this works in the same way, just a bit less confusing I think.

if( !((v >= 48 && v <= 57) || (v >= 65 && v <= 90) || (v >= 97 && v <= 122)))

However, this works also.

((v < 48 || v > 57) && (v < 65 || v > 90) && (v < 97 || v > 122))

The top function, using || (or) as a comparison, leans towards true:

(true) || (false) = (true);

But with the ! (not) added, the outcome is inverted:

!((true) || (false)) = (false);

The second function, using && (and) as a comparison, leans towards false:

(true) && (false) = (false);

@Jade thanks for helping me to get an understanding of it :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top