Reputation:
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
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
Reputation: 107307
You can use re.match()
:
import re
if re.match(r'^\d{2}\.\d{2}\.\d{4}$',input) :
#do stuff
Upvotes: 6