Validate a string format

  • Thread starter Thread starter Cralis
  • Start date Start date
C

Cralis

Hi guys,

I am a string arriving, which contains a software version.

The version comes in the form of major.minor [variant] [pre release].

So, examples are:

13.5
(The most common format)

13.5B
(A beta release)

13.5A
(Alpha release)

Is there a way to validate that the string is suitable? I'm thinking
regex, but ... can it be done that way?
 
Just to show what I have:

Regex version = new Regex("[0-9].[0-9][ab]");
if (version.IsMatch(currentVersion))
{....


I need the [ab] to be Not Required... Optional. Is that possible?
 
Just to show what I have:

Regex version = new Regex("[0-9].[0-9][ab]");
if (version.IsMatch(currentVersion))
{....

I need the [ab] to be Not Required... Optional. Is that possible?

Try:

"[0-9].[0-9][ab]?"

Arne

PS: You don't expect your software to reach 10.0??
 
Thanks!

You''re right! Now that I have found how to limit the start and end of
the string, I need to allow for > 9 as a major and minir number...

I now have this:
^[0-99].[0-9][ab]?$

Can I allow for > 10?
 
You''re right! Now that I have found how to limit the start and end of
the string, I need to allow for> 9 as a major and minir number...

I now have this:
^[0-99].[0-9][ab]?$

Can I allow for> 10?

The dash does not work like that - it is for chars
not numbers.

^[0-9]+\.[0-9][ab]?$

or:

^\d+\.\d[ab]?$

Arne
 
Back
Top