+ Start a Discussion
Joe HayesJoe Hayes 

REGEX Problem

Hi Everyone,

I have a text field that I want to start with a date in the dd/mm/yy format.

I am trying to get a REGEX validation rule to force this but I am struggling.

I need the rule to allow dd/mm/yy - *

The* will allow any text afterward.

Would someone be able to tell me the correct expression please?

Thanks
Joe
 
Best Answer chosen by Joe Hayes
Akhil AnilAkhil Anil
Hi Joe,

In that case, you can use the below formula
 
NOT(REGEX(LEFT(Name, 11),"(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]\\d\\d - "))

Also, you can check the below link to learn regex. They have got awesome stuff for beginners.

https://regexone.com/

Hope that helps !

All Answers

Vivek DVivek D
http://stackoverflow.com/questions/15491894/regex-to-validate-date-format-dd-mm-yyyy
Akhil AnilAkhil Anil
Hi Joe,

You can use the below formula to validate that your text begins with dd/mm/yy format.
 
NOT(REGEX(LEFT(Name, 8),"(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]\\d\\d"))

Replace the "Name" field with the text field that you want to validate.

Hope that helps !
Joe HayesJoe Hayes
HI Akhil,

Thanks for your help, that does work however it will also allow dd/mm/yyyy.
I need it to specifically only allow the first 11 characters to be "dd/mm/yy - "
The space hyphen space on the end is also important. After that anything can be allowed.

Not sure why but I just can't get my head round the structure of regex no matter how much I read about it.

Thank you
Joe
Akhil AnilAkhil Anil
Hi Joe,

In that case, you can use the below formula
 
NOT(REGEX(LEFT(Name, 11),"(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]\\d\\d - "))

Also, you can check the below link to learn regex. They have got awesome stuff for beginners.

https://regexone.com/

Hope that helps !
This was selected as the best answer
Joe HayesJoe Hayes
Thanks Akhil, that works perfectly.
I'll have a read of that link :)

Thank you for your help
Akhil AnilAkhil Anil
Hi Joe,

Kindly mark an answer so that we can close this thread.
Rakesh Kumar 378Rakesh Kumar 378
Hi @Akhil

I have a requirement where I need to check the format of a text field like DD/MM but we need to ensure that if we enter 02 as month then it should not allow to use any value above than 28. I am using the below mentioned validation rule and it checks every thing excep the feb month condition

AND( 
NOT(ISBLANK(EarliestStartDate__c)), 
NOT(REGEX( EarliestStartDate__c ,"(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])")) 
)

Kindly suggest