"Or" Function with JavaScript

Hello Experts,

I am managing a tool someone else developed and it's using JavaScript for form validation and I need to modify it to allow either 8 or 9 character lengths.  As you can see the code below is for 8 and I know that two pipe symbols mean "or" in JavaScript but I've been giving this a go for several hours now with no success so I thought it might be easier to just ask for some help as I am no JavaScript expert myself.

Thanks

function ValidatePurchaseRequisitionNumber() { 
    if (isNaN(NWF$("#"+jsvPurchaseRequisitionNumber).val()) == true || NWF$("#"+jsvPurchaseRequisitionNumber).val().length != 8 ) {
        alert("Purchase Requisition Number must be an 8 character number.");
        return false;
    } 
    return true;
}

Open in new window

ShadowITAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
Give this a try.  It basically checks for length less than 8 or greater than 9 as errors.

function ValidatePurchaseRequisitionNumber() { 
    if (isNaN(NWF$("#"+jsvPurchaseRequisitionNumber).val()) == true || NWF$("#"+jsvPurchaseRequisitionNumber).val().length < 8 || NWF$("#"+jsvPurchaseRequisitionNumber).val().length > 9 ) {
        alert("Purchase Requisition Number must be an 8 character number.");
        return false;
    } 
    return true;
}

Open in new window


»bp
0
 
ShadowITAuthor Commented:
Thanks so much! Worked perfectly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.