user3682248
user3682248

Reputation:

Check if the input of variable is in xx.xx.xxxx format

I have a variable "ver" whose input should be of the format xx.xx.xxxx ,valid and invalid examples below,can any one suggest how to check the input of "ver" is in this format?

VALID INPUTS:-

ver = 00.00.0009



INVALID INPUTS:-

ver = 000.0.11
ver = 00.00.002
ver = 0.0.0001
......

Upvotes: 1

Views: 1389

Answers (2)

Julien Spronck
Julien Spronck

Reputation: 15433

You can use regular expressions using the re module :

import re
valid = re.match('\d\d\.\d\d\.\d{4}', ver)
if valid:
   #...

Upvotes: 2

Kasravnd
Kasravnd

Reputation: 107307

You can use re.match() :

import re
if re.match(r'^\d{2}\.\d{2}\.\d{4}$',input) :
      #do stuff

Regular expression visualization

Debuggex Demo

Upvotes: 6

Related Questions