Conditional month & year

code

#1

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


#2

Hi @selrac,

Kindly check my example attached:

Main.xaml (6.7 KB)


#3

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


#4

@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/


#5

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


#6

For much conditions to satisfy plz look it once…

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


#7

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


#8

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


#9

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")


#10

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


#11

Hey @aksh1yadav

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


#12

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:


#13

Gotcha! I forgot to keep quotes. Thanks.


#14

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)


Workflow example for Compare PDF file
#15

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


#16

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


#17

Hi @aksh1yadav

do you have that flow?

Regards,
venkatesh