ruby - Validating version number using regex for user input -


i need validate version numbers, e.g., 6.0.2/6.0.2.011 when user enters them. checked to_i, doesn't serve purpose. can way validate version number? can let me know?

here's regular expression matches "valid" version number per specifications (only numbers separated .):

/\a\d+(?:\.\d+)*\z/ 

this expression can broken down follows:

\a        anchor expression start of string \d+       match 1 or more digit character ([0-9]) (?:       begin non-capturing group   \.      match literal dot (.) character   \d+     match 1 or more digit character )*        end group, , allow repeat 0 or more times \z        anchor expression end of string 

this expression allow . when followed @ least 1 more number, allow number of "sections" of version number (ie. 6, 6.0, 6.0.2, , 6.0.2.011 match).


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -