문제

if(!validateNumber($('input[name="age"]').val()) ){
        validate = false;
        $("#error_age").show();
        $('.field-row').has('input[name="age"]').addClass('haserror');
    }


function validateNumber(elementValue){
    var numPattern = /^[0-9]+$/;
    return numPattern.test(elementValue);   
}

Above is working code for a form in using on a competition. This isnt my code, im taking over a job and my coding knowledge is minimal.

The age input form is just age. Not DOB.

I want to be able to make it only 18 and over. How was i do this? Or whats the best way to achieve this?

Cheeers!

도움이 되었습니까?

해결책

Try something like this:

function validateNumber(elementValue){
    var numPattern = /^[0-9]+$/;
    return numPattern.test(elementValue) && elementValue >= 18;   
}

jsFiddle

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top