Download app/utils/validators.py from rastof9/fb: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/rastof9/fb/resolve/main/app/utils/validators.py
- Command line
-
hf download hf://spaces/rastof9/fb/app/utils/validators.py
-
curl -L -o validators.py https://huggingface.co/spaces/rastof9/fb/resolve/main/app/utils/validators.py
1.08 kB
| import re | |
| from flask import request, jsonify | |
| def validate_email(email): | |
| """Validate an email address.""" | |
| regex = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$" | |
| return re.match(regex, email) is not None | |
| def validate_password(password): | |
| """Validate a password (at least 8 characters, one uppercase, one number).""" | |
| if len(password) < 8: | |
| return False | |
| if not re.search(r"[A-Z]", password): | |
| return False | |
| if not re.search(r"\d", password): | |
| return False | |
| return True | |
| def validate_ad_content(content): | |
| """Validate ad content (non-empty and within length limits).""" | |
| if not content or len(content) > 1000: | |
| return False | |
| return True | |
| def validate_request_json(required_fields): | |
| """Validate JSON request payload for required fields.""" | |
| data = request.get_json() | |
| if not data: | |
| return jsonify({"error": "Request must be JSON"}), 400 | |
| for field in required_fields: | |
| if field not in data: | |
| return jsonify({"error": f"Missing required field: {field}"}), 400 | |
| return None |