I am stuck in one RegExp where I need to validate app version for app store and play-store. I have tried several RegExp but none of them is useful for me. Here are the example that pass the test
App version up-to 2-3 decimal point
1.0 // pass
1.0.0 // pass
1.0.0.0 // fail
a.0 // fail
1 // pass
I found one RegExp [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+
but this will only be valid when I have enter 4 decimal points. I don't know how to modify this.
Please help.
you have mentioned up to 2-3 decimal
then the RegExp
must be this
^(\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)?$
You can try the following regex
let reg = /^[0-9]((\.)[0-9]){0,2}$/
console.log(reg.test('1.0')) //true
console.log(reg.test('1.1.0')) //true
console.log(reg.test('1')) //true
console.log(reg.test('1.')) //false
console.log(reg.test('1.a')) //false
console.log(reg.test('1.1.1.1')) //false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With