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

Recommended Answers

All 2 Replies

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

Edit:
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.

Hi

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.

HTH

commented: Good point - maybe replace isInteger, but don't change it +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.