PDA

View Full Version : force numeric year entry to four digit year



Horizon
January 9, 2024, 11:04 PM
Is there a way to require a numeric field year to be input as 4 digits instead of 2?

So users have to enter 1990 instead of 90

Rudi
January 10, 2024, 02:39 AM
You can try to edit this code: includes/classes/rlCommon.class.php > fieldValuesAdaptation

replace:


for ($i = date('Y') + 2; $i >= 1940; $i--) {


with:


for ($i = date('y') + 2; $i >= 40; $i--) {

Horizon
January 10, 2024, 07:22 AM
Thanks! OK, I need to go back one step I think.

The field will contain (only) a 4 digit year, such as 1990.

Should the field type be created as "numeric" or "date"?

Rudi
January 10, 2024, 08:08 AM
If you need to use only years, you should create a Dropdown field and link it to Years Range

Viktor
January 10, 2024, 08:11 AM
Also you can create a new field with type number or date and use it.

Horizon
January 10, 2024, 09:59 AM
If you need to use only years, you should create a Dropdown field and link it to Years Range

Ah that makes sense. It's not quite as quick for the seller to select the year from the dropdown as typing the number, but it works to make sure the user enters something sensible!