Conditional month & year

I have to check if users have entered the date correctly in a file. The format should be like ‘MMM-YY’ like ‘FEB-17’ including the inverted comas.

the following will be incorrect:
FEB-17 ← Missing inverted comas
‘Feb-17’ ← Not capitalised
‘FEB 17’ ← Missing dash in the middle
‘FEB-2017’ ← Year should be 2 digits

Is there an easy way to validate data entry?

Thanks

Hi @selrac,

Kindly check my example attached:

Main.xaml (6.7 KB)

1 Like

Thanks for your message. This produces the output I need, but what I need to do is to validate that the users have entered the the month/year in the form that I need it

1 Like

@selrac,

First, you could also check if another string contains the entire string you need, for example:

var stringValidate = "'FEB-17'";
var stringFileName = "'FEB-17'.txt";
If  (stringFileName.Contains(stringValidate))
    MessageBox("Correct!");

Secondly, I would suggest you to create a custom regex in order to validate if a specific string contains what you are expecting and use the Matches activity in order to get the result. You could use the following website to create and test a custom regex string: http://regexr.com/

2 Likes

If I understand correctly, you are suggesting to create a kind of a vlookup with the text file containing all possible options. That could work and gives me something to work on.

Thanks

For much conditions to satisfy plz look it once…

Please revert with the response…
SAMPLE_dATE.xaml (14.6 KB)

2 Likes

Thanks Sankar. It is a great piece of code!!!

I am agree with @acaciomelo solution and you should use the different conditions based on string contains operation on it returns Boolean value based on that you can validate and for more then 2 cases it is good approach to use “Switch case activity” instead of nested if.

Just for sample quick check reference for you, consider this way as well if possible:

Regards…!!
Aksh

1 Like

You may use below way also:

strUserDate = “‘FEB-17’” ( added quotes)

strRegex = “”'(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-\d{2}'“”

boolDate = Regex.IsMatch(strUserDate,strRegex")

3 Likes

Hey @vvaidya

Slight modification:

strUserDate = “‘FEB-17’” //<" ’ FEB-17 ’ " > then this regex will work.

strRegex = “'(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-\d{2}'”

and for

strUserDate = “FEB-17”
strRegex = “(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-\d{2}”

Regards…!!
Aksh

2 Likes

Hey @aksh1yadav

I thought Mr @selrac wanted with Inverted commas, so I added the quotes to Regex.

yes but in the strUserdate there was no “quotes” with string so it will always return false in that case so just pointed out. :slight_smile:

Gotcha! I forgot to keep quotes. Thanks.

1 Like

Aksh,

I can not figure out how to make your code work. I’ve put together a simple check flow, but I’m not managing to make it work. How do you do the Redex check? I’m attaching my xaml test

StringCheck.xaml (12.8 KB)

I managed to get it working. Find xaml attached if it helps someoneStringCheck.xaml (11.6 KB)

Hey For your reference - StringCheck.xaml (11.5 KB)

try this regex - “(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-(\d{2})$”

Regards…!!
Aksh

Hi @aksh1yadav

do you have that flow?

Regards,
venkatesh