Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wrong 'or'

Status
Not open for further replies.

cjkenworthy

Programmer
Sep 13, 2002
237
GB
I'm trying to raise an error message if an input value does not begin with '09' or '08' using the following code:


var contains1 = document.frmNGN.txtNGN.value.match(/\b08/);
var contains2 = document.frmNGN.txtNGN.value.match(/\b09/);

if (!contains1 || !contains2) {
alert("A Non Geographic Number (NGN) must begin 08 or 09");
return false;
}

This doesn't appear to work because it raises the error regardless of what data is put in! It seems to work if I only use !contains1 in the condition - but i need both in.

Any help?
 
Shouldn't your "OR" test be an "AND" test?
--K
 
are you sure the entire statement is the logic you are looking for though
what it reads is
if NOT this OR NOT this THEN
Alert
else
Nothing

aren't you looking for matches though and should be reading
if this OR this THEN
Alert
else
Nothing
Then your OR logic will work

Also your alert will not work properly without the () being escaped. like this
alert("A Non Geographic Number \(NGN\) must begin 08 or 09");
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Forgot to mention if you went there to change the alert obviously on condition being met to return true else alert
here's what I mean A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top