0

G'day

I am wanting to use input[type=number] to allow 2 decimal points for input of a version number. A version number could be formatted like any one of the following; 2, 1.4, 1.0.2.

There is a similar question that resolves this for one decimal point by setting step=any. (Please take note of point not meaning the same as place)

Will I have to roll my own with javascript..

function isVersion( ver ) {
    if(!isNaN( ver ))
        return true
    else
        return !isNaN( ver.replace(/\./g, "") );
} 
console.log( isVersion( '1.3.5' ) );
Colin Palmer
  • 79
  • 1
  • 8

1 Answers1

1

No, you can't do this with input[type=number]. Version numbers like 1.0.2 are not mathematically legal.

However, you can use input[type=text] and define a proper regular expression as its pattern attribute.

For example this one matches semantic versioning numbers:

<input type="text" pattern="\d+\.\d+\.\d+">
Leo
  • 13,428
  • 5
  • 43
  • 61