javascript - Why is my || (OR) behaving like an && (and)? -
javascript - Why is my || (OR) behaving like an && (and)? -
i hoping 1 can help me here:
i want validate user input (email address) on html form. want both '@' (at sign) , '.' (period) nowadays in user input string.
here code check if case:
function email_checker(id_name){ var email = document.getelementbyid(id_name).value; if (email.indexof('@') == -1 && email.indexof('.') == -1){ code } }
the weird thing thing works || (logical or) operator instead of &&. so, suppose question doubles in sense;
a) if (logical or) works in code, why (logical and) not work?
b) why (logical or) work - work if (logical and) , not or?
(hope makes sense :)
i'm missing something. help much appreciated.
demorgan's laws answers why. if want have both, have check has@ , has.
; failure of not(has@ , has.)
, breaks downwards not(has@) or not(has.)
, can write hasnt@ or hasnt.
. current code checks hasnt@ , hasnt.
, equivalent not(has@ or has.)
(i.e. failure against rule of "has @ to the lowest degree @
or .
, not both" - not rule wanted).
javascript validation email logical-operators
Comments
Post a Comment