2

How would I write a regex to validate a particular format

lets say I have version numbers

v1.0   or v2.0

etc , my regex expression just checks for the presence of v or a number or . , how do I do a validation for a particular format in javascript

1
  • Versioning takes on many shapes. If you don't know all the permutationsd, the best you could do (in your case) is [vV][.\d]+ Commented Nov 14, 2013 at 20:10

1 Answer 1

5

You can try this regex:

/^v\d+(\.\d+)+$/i

This will match:

  1. v1.0
  2. v1.12.13
  3. v1.0.1.0.1.0.1

etc.

Sign up to request clarification or add additional context in comments.

3 Comments

This won't match v or V1 or v.5 or This is v-9.0
@sln: Slightly modified regex /^v\d+(\.\d+)*$/i can take care of it I believe.
actually I have a pretty fixed format for the version number and your first regex was perfect , Thank you for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.