Created
May 30, 2018 04:42
-
-
Save sameerkumar18/122fa318893eb3b7ad1b782b9ef81502 to your computer and use it in GitHub Desktop.
Self help - Regex Validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
To match Date such as "20-21-2018" | |
(\d{2})[/.-](\d{2})[/.-](\d{4})$ | |
To match Mobile number such as "9810284901" | |
^[0][1-9]\d{9}$|^[1-9]\d{9}$ | |
To match a URL | |
^.*http.*$ | |
''' | |
import requests | |
from cerberus import Validator | |
def validate_payload(payload): | |
# The validation schema | |
schema = { | |
'pan_number': { | |
'type': 'string', | |
'required': True, | |
'min': 10 | |
}, | |
'mobile': { | |
'type': 'string', | |
'regex': '^[0][1-9]\d{9}$|^[1-9]\d{9}$', | |
'required': True, | |
'min': 10, | |
'max': 10 | |
}, | |
'dob': { | |
'type': 'string', | |
'regex': '(\d{2})[/.-](\d{2})[/.-](\d{4})$', | |
'required': False | |
}, | |
'marital_status': { | |
'type': 'integer', | |
'required': True, | |
'min': 0, | |
'max': 2 | |
}, | |
'occupation_type': { | |
'type': 'integer', | |
'required': True, | |
'min': 0, | |
'max': 8 | |
}, | |
'address_proof': { | |
'type': 'integer', | |
'required': True, | |
'min': 0, | |
'max': 3 | |
}, | |
'signature': { | |
'type': 'string', | |
'required': True, | |
'regex': '^.*http.*$' | |
}, | |
'address_proof_image_front': { | |
'type': 'string', | |
'required': True, | |
'regex': '^.*http.*$' | |
} | |
, | |
'address_proof_image_back': { | |
'type': 'string', | |
'required': True, | |
'regex': '^.*http.*$' | |
}, | |
'pan_image': { | |
'type': 'string', | |
'required': True, | |
'regex': '^.*http.*$' | |
}, | |
'email': { | |
'type': 'string', | |
'required': True, | |
'regex': '^.*@.*$' | |
}, | |
} | |
v = Validator(schema) | |
v.allow_unknown = True | |
response = v.validate(payload) | |
print(v.errors) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment