+ Start a Discussion
anu123anu123 

text field allowing values in MM/YYYY format and should be greater than today

Hi All,

    I have a text field allowing values in MM/YYYY format only and this date should be greater than today.How to write validation rule for that. can u please any one help me .give me the sample code.

 

Thanks in advance

anu

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

try this this is better one as it checks whther the input provided by user is an applicable date or not

 

 

IF( 
OR( 
NOT(ISNUMBER(RIGHT(TextFieldAPIName__c , 4))) , 
NOT(ISNUMBER(SUBSTITUTE(LEFT( RIGHT(TextFieldAPIName__c , 7) , 2) , '/' , '') )) , 
NOT(ISNUMBER(SUBSTITUTE(LEFT(TextFieldAPIName__c , 2) , '/' , ''))), 
DATE( 
VALUE(RIGHT(TextFieldAPIName__c , 4)) , 
VALUE(SUBSTITUTE(LEFT(TextFieldAPIName__c , 2) , '/' , '')) , 
VALUE( SUBSTITUTE(LEFT( RIGHT(TextFieldAPIName__c , 7) , 2) , '/' , '') ) 
) <= TODAY() 
) 
, true , false 

)

 

All Answers

Shashikant SharmaShashikant Sharma

try this in this format is checked MM/DD/YYYY

 

IF( 
DATE( 
VALUE(RIGHT(TextFieldAPIName__c , 4)) , 
VALUE( SUBSTITUTE(LEFT( RIGHT(TextFieldAPIName__c , 7) , 2) , '/' , '') ), 
VALUE(SUBSTITUTE(LEFT(TextFieldAPIName__c , 2) , '/' , '')) 
) > TODAY() , false , true

)

 let me know if any issues in it.

Shashikant SharmaShashikant Sharma

try this this is better one as it checks whther the input provided by user is an applicable date or not

 

 

IF( 
OR( 
NOT(ISNUMBER(RIGHT(TextFieldAPIName__c , 4))) , 
NOT(ISNUMBER(SUBSTITUTE(LEFT( RIGHT(TextFieldAPIName__c , 7) , 2) , '/' , '') )) , 
NOT(ISNUMBER(SUBSTITUTE(LEFT(TextFieldAPIName__c , 2) , '/' , ''))), 
DATE( 
VALUE(RIGHT(TextFieldAPIName__c , 4)) , 
VALUE(SUBSTITUTE(LEFT(TextFieldAPIName__c , 2) , '/' , '')) , 
VALUE( SUBSTITUTE(LEFT( RIGHT(TextFieldAPIName__c , 7) , 2) , '/' , '') ) 
) <= TODAY() 
) 
, true , false 

)

 

This was selected as the best answer
anu123anu123
Thank u for ur reply.its helped me a lot
anu123anu123

Thank u for ur reply

anu123anu123

Hi Shashikant Sharma ,

         I have written above mentioned validation rule.its accepting the format like 032/2010132.i want the date only in MM/YYYY format only allowed. i try to solve that .but its not getting.please can u make the changes. and give me the sample code.please can u help me.

 

 

thanks in advance.

anu