You need to sign in to do that
Don't have an account?

Number field validation with year and month
Hi,
I've a field called "Year_Month__c" of datatype "Number".
the value for this field should be like 201510 meaning yyyymm. I need to have a validation rule which validates first four digits are valid year or not and last 2 digits should be a valid month. If someone enters, 201078 - it should throw an error as month is not valid.
Can anyone help me in achieving this validation rule for number field.
Thanks in advance.
Vasavi
I've a field called "Year_Month__c" of datatype "Number".
the value for this field should be like 201510 meaning yyyymm. I need to have a validation rule which validates first four digits are valid year or not and last 2 digits should be a valid month. If someone enters, 201078 - it should throw an error as month is not valid.
Can anyone help me in achieving this validation rule for number field.
Thanks in advance.
Vasavi
NOT(
REGEX(Text(Year_Month__c), "[0-9]{4}(0[1-9]|1[012])")
)
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
All Answers
NOT(
REGEX(Text(Year_Month__c), "[0-9]{4}(0[1-9]|1[012])")
)
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
Thanks,
Vasavi
It assumes that "Year_Month__c" of datatype "Number" as you stated. Yes it assumes YYYYMM otherwise it will error out.
REGEX just validates that the value has to be a certain format otherwise it will give a validation error.
Thx