I need to validate file name with following pattern….
- File name(string) should not be null or empty
- File name(string) should have extension as .INI
- File name(string) should have “gen1” or “gen2” or “gen3″… genN where N has to be number.
We have already done the implementation with Javascript string functions but it looked little messy..
I am really interested in Validation-3 of “genN” which can be done more gracefully with RegEx
By “should have
genN“, do you mean:Should be named gen#.ini?
Should contain
gen#?Also, if you want more than
0to9in those, change\dto\d+. If you only want to accept 1 and onwards,[1-9]. Both these requirements?[1-9]\d*.Here’s a helpful picker that should make the right regular expression for you.