46 lines
1.7 KiB
Diff
46 lines
1.7 KiB
Diff
From 77f2c6a864baac31d7e6b4bee924dad82214092c Mon Sep 17 00:00:00 2001
|
|
From: rabbitali <wenxin32@foxmail.com>
|
|
Date: Wed, 20 Dec 2023 15:37:29 +0800
|
|
Subject: [PATCH] update ValidateRules
|
|
|
|
---
|
|
vulcanus/restful/serialize/validate.py | 14 ++++++++++++--
|
|
1 file changed, 12 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/vulcanus/restful/serialize/validate.py b/vulcanus/restful/serialize/validate.py
|
|
index d6eacbe..3050693 100644
|
|
--- a/vulcanus/restful/serialize/validate.py
|
|
+++ b/vulcanus/restful/serialize/validate.py
|
|
@@ -64,7 +64,7 @@ class ValidateRules:
|
|
"""
|
|
validation rules for username, which only contains string or number
|
|
"""
|
|
- if not re.findall("[a-zA-Z0-9]{5,20}", string):
|
|
+ if not re.findall("^[a-zA-Z0-9]{5,20}$", string):
|
|
raise ValidationError("username should only contains string or number, between 5 and 20 characters!")
|
|
|
|
@staticmethod
|
|
@@ -72,8 +72,18 @@ class ValidateRules:
|
|
"""
|
|
validation rules for password, which only contains string or number
|
|
"""
|
|
- if not re.findall("[a-zA-Z0-9]{6,20}", string):
|
|
+ if not re.findall("^[a-zA-Z0-9]{6,20}$", string):
|
|
raise ValidationError("password should only contains string or number, between 6 and 20 characters!!")
|
|
+
|
|
+ @staticmethod
|
|
+ def ipv4_address_check(string: str):
|
|
+ """
|
|
+ validation rules for IPV4 address
|
|
+ """
|
|
+ ipv4_address_pattern = r"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
|
+ if not re.findall(ipv4_address_pattern, string):
|
|
+ raise ValidationError("Not a valid IPV4 address.")
|
|
+
|
|
|
|
|
|
class PaginationSchema(Schema):
|
|
--
|
|
2.33.0
|
|
|