Question

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!

Was it helpful?

Solution

Try something like this:

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

jsFiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top