Click to See Complete Forum and Search --> : not equal to


ronke
01-15-2003, 02:18 PM
quick one ... how can i say a the length of a field can be either 6 or 8, nothing else.

Thanks for your response.

gil davis
01-15-2003, 02:24 PM
var st = document.formName.fieldName.value;
if ((st.length == 6) || (st.length == 8))
{ // do your thing}
else
{ // error}

pyro
01-15-2003, 02:46 PM
Just to show another way...

if (str.length != 6 || 8)

Dan Drillich
01-15-2003, 03:20 PM
I have some doubts about the
if (str.length != 6 || 8) syntax.
Doesn't work for me in IE 5.

Cheers,
Dan

Zach Elfers
01-15-2003, 03:31 PM
pyro, that should be:

if (str.length != 6 || str.length != 8) {

pyro
01-15-2003, 03:41 PM
Color me surprised! Your're right Dan, it doesn't work. Guess I should have tested it before I posted. You will have to use Gil's method.

BTW Zach, your way doesn't work, either...

Zach Elfers
01-15-2003, 03:45 PM
Yes it will, if you do it like this:

function length() {
if (str.length != 6 || str.length != 8) {
alert("The field must contain either 6 or 8 characters.);
str.focus();
}
}

...

<input type="button" value="Send" onClick="length();">