1

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' ) );
1

1 Answer 1

2

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+">
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, perfect answer, the pattern I'm using is "(\d+\.\d+\.\d+)|(\d+\.\d+)|(\d+)"

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.