Hi All,

I have an online screen in which a form filed is filled with Numeric Characters .. if the entered four digits are not numeric, it will throw an alert message saying "Only numerics allowed".

Now the new requirement is it should accept alphanumeric characeters instead of Numeric Characters.

Below is the code which is used to check the value.

    if (vic.value.length != 4 || !isInteger(vic.value))
        alert ("VIC is required (4 numeric digits).");
        return false;   

How do i change this condition to check for Alpha Numeric Characters instead of Numeric.

Thanks in Advance

The check is obviously done in your isInteger method, so you need to change that.

djjeavons makes a good point. My advice above is bad. Don't change isInteger - maybe create a new isAlphanumeric method to parallel isInteger but with the tests you need.


Rather than changing the isInteger method (which may be used elsewhere), if you want to allow alphanumeric characters, just remove the isInteger check in your code:

if (vic.value.length != 4)
    alert ("VIC is required (4 alphanumeric digits).");
    return false;   

Not sure if you have other requirements such as only allowing a-z and 0-9.


Good point - maybe replace isInteger, but don't change it
This question has already been answered. Start a new discussion instead.