Link to home
Create AccountLog in
Avatar of -Dman100-
-Dman100-Flag for United States of America

asked on

error validating number 4 or 5 digits

I am hoping a javascript guru can help me debug a problem with a validation function.  I have a simple javascript function that validates an input that must be numeric and 4 or 5 digits.  However, it appears to be causing errors.

See below for the validation function.

Thanks for any help.
This code causes errors:

function checkemployeenumber(input) {
        var str=input.value;
        var filter = /^[0-9]{4,5}$/;

        if (filter.test(str)) {
            return true;
        }else{
            return false;
        }
    }

If I change to just validate 5 digits like this it works:

function checkemployeenumber(input) {
        var str=input.value;
        var filter = /^[0-9]{5}$/;

        if (filter.test(str)) {
            return true;
        }else{
            return false;
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jrm213jrm213
jrm213jrm213
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of -Dman100-

ASKER

Thanks for the help guys.  I determined it was another issue and not the javascript.  Thanks for your help!  I appreciate it.
Thank you for the assist, and the points.

Good luck & have a great day.