javascript - Version number validation -


my product version number of format "p.q.r", p, q, r digits. valid inputs "p", "p.q", "p.q.r".

i wrote regular expression performing or operation.

(^\d+$) | (^\d+.\d+$) | (^\d+.\d+.\d$) 

is there simpler way write using javascript ?

the following regex should work:

^\d+(\.\d+){0,2}$ 

the \d+ indicates number of digits. (\.\d+) indicates dot followed number of digits, , {0,2} means last group can repeated 0-2 times. ^ , $ indicate start , end of string, regex match whole thing.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -