Hi, I wrote a regular expression to check where a string is of type char - or. or / or: or AM or PM or a space. Regex follworig is used for this, but I want to make case fail if the string contains char, except for AMP. import re
Datere = re.compile("[-./\:?AMP ]+")
FD = { 'Date' : lambda date : bool(re.search(Datere,date)),}
def Validate(date):
for k,v in date.iteritems():
print k,v
print FD.get(k)(v)
Conclusion:
Validate({'Date':'12/12/2010'})
Date 12/12/2010
True
Validate({'Date':'12/12/2010 12:30 AM'})
Date 12/12/2010
True
Validate({'Date':'12/12/2010 ZZ'})
Date 12/12/2010
True (Expecting False)
Edited: Check ({'Date': '12122010'}) Date 12122010 False (Waiting False)
How can I find a string other than char APM, any suggestion. Many thanks.
source
share