Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Regex for fiscal year

Prvn1
Tera Contributor

What would be the regex for validating a fiscal year ?

 

ex: Q2FY24 or q2fy24

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Prvn1 Here is the Regex to validate the fiscal year.

 

^Q[1-4]FY[0-9][0-9]$|q[1-4]fy[0-9][0-9]$

 

Please mark this answer helpful and correct if it address your requirement.

SN_Learn
Kilo Patron
Kilo Patron

Hi @Prvn1 ,

 

One of the Regex codes for the fiscal year validation is as below:

 

 

 

var pattern = /^[Qq][1-4]FY\d{2}$/i;

function validateFiscalYear(fiscalYear) {
return pattern.test(fiscalYear);
}

var fiscalYearToValidate = "Q4FY20"; // Replace with the fiscal year you want to check

if (validateFiscalYear(fiscalYearToValidate)) {
gs.info(fiscalYearToValidate + " is a valid fiscal year.");
} else {
gs.info(fiscalYearToValidate + " is not a valid fiscal year.");
}

 

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Amit Gujarathi
Giga Sage
Giga Sage

HI @Prvn1 ,
I trust you are doing great.
Please find the below regex for the same :

^[Qq][1-4][Ff][Yy]\d{2}$

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi