Skip to content
Advertisement

REGEX to match only VALID EXCEL COLUMNS (A-XFD)

Ok, I have ANOTHER REGEX question for everyone.

I have a field that has multiple validation steps. The first step is to ensure it isn’t blank, second is to ensure that only between 1 and 3 CAPITAL LETTERS are entered, and third, to ensure it doesn’t contain “[” (an opening bracket will denote a function in this scenario and we skip validation). All of this works. Now, I have to ensure that the value being entered is only a valid Excel Column Reference. Valid Excel Columns can be the letters A – XFD.

I am currently using:

JavaScript

any further direction will be much appreciated as I have been through regex tuts for hours now and am lost.

I had been given help on a similar issue in the past and my poor attempt to emulate the function that was provided then is as follows:

JavaScript

it doesn’t work…please help

Advertisement

Answer

Since you’ve already determined that the value is 1-3 alphabetic characters, how about:

JavaScript

Any value with 2 or less letters should be acceptable, and for the case of three letters, alphabetic comparison is adequate.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement